doukui 0.6.0 → 0.8.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 (44) hide show
  1. package/README.md +27 -67
  2. package/bin/commands/help.js +0 -25
  3. package/bin/doukui.js +1 -3
  4. package/package.json +2 -3
  5. package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +261 -0
  6. package/plugins/core/skill-agent-dispatcher/recovery-reference.md +91 -0
  7. package/plugins/core/skill-agent-dispatcher/skill.md +39 -299
  8. package/plugins/core/skill-agentic-loop/mirror-rules.md +82 -23
  9. package/plugins/core/skill-agentic-loop/plugin.json +2 -7
  10. package/plugins/core/skill-agentic-loop/skill.md +49 -77
  11. package/plugins/core/skill-completion-report/skill.md +7 -1
  12. package/plugins/core/skill-doukui-plan/skill.md +3 -0
  13. package/plugins/plugin-registry.json +0 -12
  14. package/plugins/runtime/plan-reader.js +33 -18
  15. package/plugins/runtime/text-tokenize.js +1 -2
  16. package/templates/harness-config.yaml +0 -100
  17. package/bin/commands/loop-server.js +0 -357
  18. package/bin/commands/loop.js +0 -1508
  19. package/plugins/contracts/checkresult-schema.json +0 -75
  20. package/plugins/core/provider-loop-engine/index.js +0 -1411
  21. package/plugins/core/provider-loop-engine/plugin.json +0 -15
  22. package/plugins/runtime/checkresult-validator.js +0 -131
  23. package/plugins/runtime/context-window.js +0 -81
  24. package/plugins/runtime/executor-claude.js +0 -604
  25. package/plugins/runtime/executor-default.js +0 -448
  26. package/plugins/runtime/executor-local.js +0 -178
  27. package/plugins/runtime/executor-sdk.js +0 -415
  28. package/plugins/runtime/loop-actuator.js +0 -292
  29. package/plugins/runtime/loop-coordinator.js +0 -347
  30. package/plugins/runtime/loop-defaults.js +0 -29
  31. package/plugins/runtime/loop-dispatch-batch.js +0 -351
  32. package/plugins/runtime/loop-executor.js +0 -120
  33. package/plugins/runtime/loop-report.js +0 -395
  34. package/plugins/runtime/loop-server-core.js +0 -750
  35. package/plugins/runtime/loop-snapshot.js +0 -581
  36. package/plugins/runtime/loop-trace.js +0 -242
  37. package/plugins/runtime/loop-worktree.js +0 -404
  38. package/plugins/runtime/multi-window-coordinator.js +0 -560
  39. package/plugins/runtime/objective-verifier.js +0 -136
  40. package/plugins/runtime/plan-lint.js +0 -106
  41. package/plugins/runtime/provider-failover.js +0 -114
  42. package/plugins/runtime/provider-resolver.js +0 -342
  43. package/plugins/runtime/reflection-evaluator.js +0 -545
  44. package/plugins/runtime/self-rescue-ladder.js +0 -51
@@ -1,395 +0,0 @@
1
- /**
2
- * Loop Report — Agentic Loop 触顶总结报告生成器(WP-177-1-impl-c)
3
- *
4
- * @module loop-report
5
- *
6
- * 从 loop 运行状态(state.history 各轮 verdict/proximity/failedCount)+ 当前失败项
7
- * 明细(state.failingDrivers / state.lastEval.failingDrivers)生成结构化总结报告。
8
- *
9
- * 当 loop 触顶(timeout)/发散(diverged)/熔断(circuit_broken)时由 engine 出口行为
10
- * (WP-177-2-impl-c)或 skill.md Step 5(WP-177-3-impl-b)调用,直接输出给用户,
11
- * 替代「回 P1 human-checkpoint」。
12
- *
13
- * 本模块是纯函数式(输入 state,输出报告),无副作用、无 IO,易于测试。
14
- * 本模块只负责「报告内容」;「是否回 P1」是 engine 出口 / skill.md 的决策,不在此决定。
15
- *
16
- * 数据来源:
17
- * - state.history(engine step 每轮写入,provider-loop-engine/index.js step())
18
- * 每项形如 { iteration, eval:{ proximity, converged, diverged, failedCount }, verdict, timestamp }
19
- * - state.failingDrivers(Reflect 回填,reflection-evaluator.js → engine reflect)
20
- * 每项形如 { wpId, category, item, reason }
21
- * - state.lastEval.failingDrivers(降级取最近一次 EvalResult)
22
- *
23
- * 设计依据:docs/wp/WP-177.md(改造目标第 5 条「停下输出报告」)、
24
- * docs/wp/WP-177-1-impl-c.md
25
- */
26
-
27
- 'use strict';
28
-
29
- // ---------------------------------------------------------------------------
30
- // 默认配置
31
- // ---------------------------------------------------------------------------
32
-
33
- var DEFAULTS = {
34
- // markdown 趋势表只显示最近 N 轮,避免过长(proximityTrend 结构体仍含全部轮次)
35
- trendTableLimit: 10,
36
- };
37
-
38
- // 三种终态 verdict 对应的「建议下一步」文案(design.md 出口行为)
39
- var VERDICT_SUMMARIES = {
40
- timeout: '已达轮次上限未达成,可手动修复剩余失败项或调高 max_iterations',
41
- diverged: '连续多轮无进展,建议调整目标或拆分失败 WP',
42
- circuit_broken: '守护异常,建议检查 watchdog/dispatcher 健康后重试',
43
- };
44
-
45
- // ---------------------------------------------------------------------------
46
- // 工具函数
47
- // ---------------------------------------------------------------------------
48
-
49
- /**
50
- * ISO 时间戳。
51
- * @returns {string}
52
- */
53
- function nowIso() {
54
- return new Date().toISOString();
55
- }
56
-
57
- /**
58
- * 从 state.history 提取按 iteration 排序的 proximity 趋势(design.md §5.3.1)。
59
- * 每项形如 { iteration, proximity, verdict, failedCount }。
60
- *
61
- * history 通常按追加顺序,但保险起见按 iteration 排序。缺失 eval / proximity 的轮次
62
- * 被跳过(不破坏趋势序列连续性,但 iteration 仍反映真实轮次)。
63
- *
64
- * @param {object} state
65
- * @returns {Array<{iter:number, proximity:number, verdict:string, failedCount:number|null}>}
66
- */
67
- function extractProximityTrend(state) {
68
- if (!state || !state.history || !state.history.length) return [];
69
- var sorted = state.history.slice().sort(function (a, b) {
70
- var ia = (a && typeof a.iteration === 'number') ? a.iteration : 0;
71
- var ib = (b && typeof b.iteration === 'number') ? b.iteration : 0;
72
- return ia - ib;
73
- });
74
- var out = [];
75
- for (var i = 0; i < sorted.length; i++) {
76
- var entry = sorted[i];
77
- if (!entry) continue;
78
- var ev = entry.eval || {};
79
- out.push({
80
- iter: (typeof entry.iteration === 'number') ? entry.iteration : 0,
81
- proximity: (typeof ev.proximity === 'number') ? ev.proximity : null,
82
- verdict: entry.verdict || '',
83
- failedCount: (typeof ev.failedCount === 'number') ? ev.failedCount : null,
84
- });
85
- }
86
- return out;
87
- }
88
-
89
- /**
90
- * 从 state 提取最新失败项明细(failingDrivers)。
91
- * 优先 state.failingDrivers(Reflect 回填),回退 state.lastEval.failingDrivers。
92
- * 归一化为 { wpId, category, item, reason }。
93
- *
94
- * @param {object} state
95
- * @returns {Array<{wpId:string, category:string, item:string, reason:string}>}
96
- */
97
- function extractFailedItems(state) {
98
- var raw = [];
99
- if (state) {
100
- if (state.failingDrivers && state.failingDrivers.length) {
101
- raw = state.failingDrivers;
102
- } else if (state.lastEval && state.lastEval.failingDrivers && state.lastEval.failingDrivers.length) {
103
- raw = state.lastEval.failingDrivers;
104
- }
105
- }
106
- var out = [];
107
- for (var i = 0; i < raw.length; i++) {
108
- var d = raw[i];
109
- if (!d) continue;
110
- out.push({
111
- wpId: d.wpId || '',
112
- category: d.category || '',
113
- item: d.item || '',
114
- reason: d.reason || '',
115
- });
116
- }
117
- return out;
118
- }
119
-
120
- /**
121
- * 归一化 verdict:未知值降级为 'timeout'(最小可用终态)。
122
- * @param {string} verdict
123
- * @returns {string}
124
- */
125
- function normalizeVerdict(verdict) {
126
- if (verdict && VERDICT_SUMMARIES[verdict]) return verdict;
127
- // 兜底:未明确终态时按 timeout 处理(最常见出口)
128
- return 'timeout';
129
- }
130
-
131
- /**
132
- * 构建一句话结论 summary。
133
- * @param {object} opts { verdict, iteration, failedCount, lastProximity }
134
- * @returns {string}
135
- */
136
- function buildSummary(opts) {
137
- var verdict = opts.verdict;
138
- var iter = opts.iteration;
139
- var failedCount = opts.failedCount;
140
- var lastProximity = opts.lastProximity;
141
- var base = VERDICT_SUMMARIES[verdict] || VERDICT_SUMMARIES.timeout;
142
- var parts = [];
143
- parts.push('Agentic Loop 在第 ' + iter + ' 轮以「' + verdict + '」终止。');
144
- if (typeof lastProximity === 'number') {
145
- parts.push('最终 proximity=' + lastProximity.toFixed(2) + '。');
146
- }
147
- if (typeof failedCount === 'number' && failedCount > 0) {
148
- parts.push('剩余失败项 ' + failedCount + ' 个。');
149
- }
150
- parts.push(base);
151
- return parts.join(' ');
152
- }
153
-
154
- // ---------------------------------------------------------------------------
155
- // markdown 渲染
156
- // ---------------------------------------------------------------------------
157
-
158
- /**
159
- * 把 proximity 趋势渲染为 markdown 表格(最近 N 轮)。
160
- * @param {Array} trend proximityTrend
161
- * @param {number} limit 最近 N 轮
162
- * @returns {string} markdown 片段(含表头),无数据时返回提示行
163
- */
164
- function renderTrendTable(trend, limit) {
165
- if (!trend || !trend.length) {
166
- return '_(无历史轮次数据)_';
167
- }
168
- var n = (typeof limit === 'number' && limit > 0) ? limit : DEFAULTS.trendTableLimit;
169
- var slice = trend.length > n ? trend.slice(trend.length - n) : trend;
170
- var lines = [];
171
- lines.push('| 轮次 | proximity | 失败项数 | verdict |');
172
- lines.push('|------|-----------|----------|---------|');
173
- for (var i = 0; i < slice.length; i++) {
174
- var r = slice[i];
175
- var prox = (typeof r.proximity === 'number') ? r.proximity.toFixed(2) : '-';
176
- var fc = (typeof r.failedCount === 'number') ? String(r.failedCount) : '-';
177
- var vd = r.verdict || '-';
178
- lines.push('| ' + r.iter + ' | ' + prox + ' | ' + fc + ' | ' + vd + ' |');
179
- }
180
- if (trend.length > n) {
181
- lines.push('');
182
- lines.push('_(仅显示最近 ' + n + ' 轮,共 ' + trend.length + ' 轮)_');
183
- }
184
- return lines.join('\n');
185
- }
186
-
187
- /**
188
- * 把失败项明细渲染为 markdown 表格。
189
- * @param {Array} failedItems
190
- * @returns {string} markdown 片段(含表头),无数据时返回提示行
191
- */
192
- function renderFailedItemsTable(failedItems) {
193
- if (!failedItems || !failedItems.length) {
194
- return '_(无失败项明细)_';
195
- }
196
- var lines = [];
197
- lines.push('| WP | 类别 | 检查项 | 原因 |');
198
- lines.push('|----|------|--------|------|');
199
- for (var i = 0; i < failedItems.length; i++) {
200
- var f = failedItems[i];
201
- lines.push(
202
- '| ' + (f.wpId || '-') + ' | ' + (f.category || '-') +
203
- ' | ' + (f.item || '-') + ' | ' + (f.reason || '-') + ' |'
204
- );
205
- }
206
- return lines.join('\n');
207
- }
208
-
209
- /**
210
- * 渲染完整 markdown 报告。
211
- * @param {object} report 结构化报告对象
212
- * @param {number} [trendTableLimit] markdown 趋势表显示最近 N 轮
213
- * @returns {string}
214
- */
215
- function renderMarkdown(report, trendTableLimit) {
216
- var lines = [];
217
- lines.push('## Agentic Loop 终止报告');
218
- lines.push('');
219
- lines.push('**Loop ID**: `' + report.loopId + '`');
220
- lines.push('**终止原因**: ' + report.verdict);
221
- lines.push('**迭代轮次**: ' + report.iteration);
222
- lines.push('**生成时间**: ' + report.generatedAt);
223
- lines.push('');
224
- lines.push('### 结论');
225
- lines.push('');
226
- lines.push(report.summary);
227
- lines.push('');
228
- lines.push('### Proximity 趋势');
229
- lines.push('');
230
- var limit = (typeof trendTableLimit === 'number' && trendTableLimit > 0)
231
- ? trendTableLimit : DEFAULTS.trendTableLimit;
232
- lines.push(renderTrendTable(report.proximityTrend, limit));
233
- lines.push('');
234
- lines.push('### 失败项明细');
235
- lines.push('');
236
- lines.push(renderFailedItemsTable(report.failedItems));
237
- lines.push('');
238
- lines.push('### 建议下一步');
239
- lines.push('');
240
- lines.push('- ' + (VERDICT_SUMMARIES[report.verdict] || VERDICT_SUMMARIES.timeout));
241
- lines.push('');
242
- return lines.join('\n');
243
- }
244
-
245
- // ---------------------------------------------------------------------------
246
- // 公开 API
247
- // ---------------------------------------------------------------------------
248
-
249
- module.exports = {
250
- /**
251
- * 生成触顶/发散/熔断总结报告(纯函数,无副作用)。
252
- *
253
- * @param {object} state LoopState(design.md §5.1.1),至少含 history / failingDrivers
254
- * @param {object} [opts] 可选参数
255
- * @param {string} [opts.loopId] 覆盖 state.loopId(出口调用方已知 loopId 时更可靠)
256
- * @param {string} [opts.verdict] 覆盖终态判定(出口调用方决定权优先)
257
- * @param {number} [opts.trendTableLimit] markdown 趋势表显示最近 N 轮
258
- * @returns {object} 报告对象:
259
- * {
260
- * loopId, verdict, iteration, proximityTrend, failedItems,
261
- * summary, markdown, lastProximity, failedCount, generatedAt
262
- * }
263
- */
264
- /**
265
- * 生成降级交付报告(v0.4.0 A1——北极星 1 终态语义:自救梯穷尽后不是「停下等人」,
266
- * 已完成 WP 照常交付 + 未完成项交接明细,人拿到的是「部分成果 + 接手清单」)。
267
- *
268
- * 内部复用 generateTerminalReport(趋势/失败项明细同源),追加交付清单段。
269
- * 纯函数,无副作用。
270
- *
271
- * @param {object} state LoopState(同 generateTerminalReport)
272
- * @param {object} [opts]
273
- * @param {string[]} [opts.completedWps] 已完成 WP 列表(driver 从 PROGRESS.md 读)
274
- * @param {string[]} [opts.goalWps] 全量目标 WP(缺省时 pending = goal - completed - failed 推导不出,仅展示两清单)
275
- * @returns {object} 报告对象(含 terminal 基础字段 + delivered/pendingWps/markdown)
276
- */
277
- generateDegradedDeliveryReport: function (state, opts) {
278
- opts = opts || {};
279
- var base = module.exports.generateTerminalReport(state, opts);
280
- var completedWps = Array.isArray(opts.completedWps) ? opts.completedWps : [];
281
- var goalWps = Array.isArray(opts.goalWps) ? opts.goalWps : [];
282
-
283
- // 未完成 WP = goal 范围内非 completed 的(failedItems 的 wpId 并集优先展示失败原因)
284
- var pendingWps = [];
285
- for (var i = 0; i < goalWps.length; i++) {
286
- if (completedWps.indexOf(goalWps[i]) === -1) pendingWps.push(goalWps[i]);
287
- }
288
-
289
- var lines = [];
290
- lines.push('## Agentic Loop 降级交付报告');
291
- lines.push('');
292
- lines.push('**Loop ID**: `' + base.loopId + '` · **终止原因**: ' + base.verdict +
293
- ' · **自救链已穷尽**(切换/重置均试过,未达成)');
294
- lines.push('');
295
- lines.push('### ✅ 已交付(' + completedWps.length + ' 个 WP,成果已生效)');
296
- lines.push('');
297
- if (completedWps.length) {
298
- for (var c = 0; c < completedWps.length; c++) lines.push('- ' + completedWps[c]);
299
- } else {
300
- lines.push('(无已通过 checklist 的 WP)');
301
- }
302
- lines.push('');
303
- lines.push('### ⏳ 未完成(' + pendingWps.length + ' 个 WP,需人接手或重启 loop)');
304
- lines.push('');
305
- if (pendingWps.length) {
306
- for (var p = 0; p < pendingWps.length; p++) lines.push('- ' + pendingWps[p]);
307
- } else {
308
- lines.push('(无)');
309
- }
310
- lines.push('');
311
- lines.push('### 失败项明细(接手修复的切入点)');
312
- lines.push('');
313
- lines.push(renderFailedItemsTable(base.failedItems));
314
- lines.push('');
315
- lines.push('### Proximity 趋势(最近 ' + DEFAULTS.trendTableLimit + ' 轮)');
316
- lines.push('');
317
- lines.push(renderTrendTable(base.proximityTrend, DEFAULTS.trendTableLimit));
318
- lines.push('');
319
- lines.push('### 建议下一步');
320
- lines.push('');
321
- lines.push('- 优先按失败项明细修复未完成 WP(上文 ⏳ 清单),再对剩余 WP 重跑 `doukui loop`(PROGRESS.md 已记完成项,不会重做)');
322
- lines.push('- ' + (VERDICT_SUMMARIES[base.verdict] || VERDICT_SUMMARIES.timeout));
323
- lines.push('');
324
-
325
- base.delivered = completedWps;
326
- base.pendingWps = pendingWps;
327
- base.markdown = lines.join('\n');
328
- base.degradedDelivery = true;
329
- return base;
330
- },
331
-
332
- generateTerminalReport: function (state, opts) {
333
- // 容错:state 完全缺失 → 降级最小报告,不抛异常
334
- state = state || {};
335
- opts = opts || {};
336
-
337
- var loopId = opts.loopId || state.loopId || '';
338
- var verdict = normalizeVerdict(opts.verdict || state.lastVerdictVerdict ||
339
- (state.lastVerdict && state.lastVerdict.verdict) || state.status);
340
-
341
- var iteration = (typeof state.iteration === 'number') ? state.iteration : 0;
342
-
343
- var proximityTrend = extractProximityTrend(state);
344
- var failedItems = extractFailedItems(state);
345
-
346
- // 最终 proximity / 失败项数:优先趋势末轮,回退 lastEval
347
- var lastProximity = null;
348
- if (proximityTrend.length) {
349
- lastProximity = proximityTrend[proximityTrend.length - 1].proximity;
350
- } else if (state.lastEval && typeof state.lastEval.proximity === 'number') {
351
- lastProximity = state.lastEval.proximity;
352
- }
353
- var failedCount = failedItems.length;
354
- if (typeof failedCount !== 'number') failedCount = 0;
355
-
356
- var summary = buildSummary({
357
- verdict: verdict,
358
- iteration: iteration,
359
- failedCount: failedCount,
360
- lastProximity: lastProximity,
361
- });
362
-
363
- // 趋势表行数:opts 覆盖默认(局部变量,不污染模块级 DEFAULTS,保持纯函数)
364
- var trendTableLimit = (typeof opts.trendTableLimit === 'number' && opts.trendTableLimit > 0)
365
- ? opts.trendTableLimit : DEFAULTS.trendTableLimit;
366
-
367
- var report = {
368
- loopId: loopId,
369
- verdict: verdict,
370
- iteration: iteration,
371
- proximityTrend: proximityTrend,
372
- failedItems: failedItems,
373
- lastProximity: lastProximity,
374
- failedCount: failedCount,
375
- summary: summary,
376
- markdown: '',
377
- generatedAt: nowIso(),
378
- };
379
-
380
- report.markdown = renderMarkdown(report, trendTableLimit);
381
-
382
- return report;
383
- },
384
-
385
- // 暴露内部工具便于单元测试
386
- _extractProximityTrend: extractProximityTrend,
387
- _extractFailedItems: extractFailedItems,
388
- _normalizeVerdict: normalizeVerdict,
389
- _buildSummary: buildSummary,
390
- _renderTrendTable: renderTrendTable,
391
- _renderFailedItemsTable: renderFailedItemsTable,
392
- _renderMarkdown: renderMarkdown,
393
- _VERDICT_SUMMARIES: VERDICT_SUMMARIES,
394
- _DEFAULTS: DEFAULTS,
395
- };