doukui 0.5.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 -99
  17. package/bin/commands/loop-server.js +0 -357
  18. package/bin/commands/loop.js +0 -1510
  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 -247
  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,15 +0,0 @@
1
- {
2
- "name": "provider-loop-engine",
3
- "version": "1.0.0",
4
- "type": "provider",
5
- "description": "Agentic Loop 决策状态机 Provider - Observe/Think/Act/Reflect/Decide 循环核心,复用 state-store 持久化",
6
- "dependencies": ["provider:state-store", "provider:watchdog"],
7
- "provides": ["provider:loop-engine"],
8
- "config": {
9
- "max_iterations": 6,
10
- "max_round_time_ms": 600000,
11
- "max_wall_time_ms": 3600000,
12
- "divergence_threshold": 3,
13
- "proximity_goal": 0.9
14
- }
15
- }
@@ -1,131 +0,0 @@
1
- 'use strict';
2
-
3
- // ---------------------------------------------------------------------------
4
- // CheckResult 客户端校验层(Phase D-1)
5
- // ---------------------------------------------------------------------------
6
- // 原信任模型:proximity/summary 全部来自 LLM 自报的 fenced block,无独立校验,
7
- // 已出现真实谎报(reflection-evaluator B19「passed > total 钳 0」补丁)。本层在
8
- // executor 解析链内做客户端校验,把谎报/瑕疵在进入评分前暴露:
9
- //
10
- // 分级处理:
11
- // - hard(数值谎报:passed+failed≠total、passed>total、负数)→ 调用方**硬改判**
12
- // failed(B19 类问题的系统性替代——在源头修,不靠下游钳制)
13
- // - 非 hard(结构瑕疵:缺 categories、item 缺 id 等)→ 仅告警(_schemaErrors
14
- // 附加到 trace,observability),不改判——避免误伤轻微不合规的可用输出
15
- //
16
- // ajv 为主路径(optionalDependency,缺失时走内置校验,零强制依赖)。
17
- // ---------------------------------------------------------------------------
18
-
19
- var fs = require('fs');
20
- var path = require('path');
21
-
22
- var SCHEMA_PATH = path.join(__dirname, '..', 'contracts', 'checkresult-schema.json');
23
-
24
- var _ajv = null;
25
- var _ajvProbed = false;
26
- var _validateFn = null;
27
-
28
- function loadAjvValidator() {
29
- if (_ajvProbed) return _validateFn;
30
- _ajvProbed = true;
31
- try {
32
- var Ajv = require('ajv');
33
- var schema = JSON.parse(fs.readFileSync(SCHEMA_PATH, 'utf8'));
34
- // json-schema draft-07;ajv 8 需要 addMetaSchema 或显式指定 —— 传 schema 即可
35
- var ajv = new Ajv({ allErrors: true });
36
- _validateFn = ajv.compile(schema);
37
- } catch (_e) {
38
- _validateFn = null; // ajv 未安装或 schema 损坏 → 内置校验
39
- }
40
- return _validateFn;
41
- }
42
-
43
- /** 测试用:重置 ajv 探测缓存 */
44
- function _resetValidatorCache() {
45
- _ajvProbed = false;
46
- _validateFn = null;
47
- }
48
-
49
- /**
50
- * 内置最小校验(ajv 缺失时的降级路径):必填字段 + 数值一致性。
51
- * @param {object} raw
52
- * @returns {string[]} 错误列表(空数组 = 合法)
53
- */
54
- function builtinValidate(raw) {
55
- var errors = [];
56
- if (!raw || typeof raw !== 'object') {
57
- errors.push('not an object');
58
- return errors;
59
- }
60
- if (typeof raw.wpId !== 'string' || !raw.wpId) errors.push('wpId: required string');
61
- if (typeof raw.passed !== 'boolean') errors.push('passed: required boolean');
62
- var s = raw.summary;
63
- if (!s || typeof s !== 'object') {
64
- errors.push('summary: required object');
65
- } else {
66
- var total = s.total, passed = s.passed, failed = s.failed;
67
- if (typeof total !== 'number' || total < 0) errors.push('summary.total: non-negative integer required');
68
- if (typeof passed !== 'number' || passed < 0) errors.push('summary.passed: non-negative integer required');
69
- if (typeof failed !== 'number' || failed < 0) errors.push('summary.failed: non-negative integer required');
70
- if (typeof total === 'number' && typeof passed === 'number' && typeof failed === 'number' && total >= 0) {
71
- if (passed > total) errors.push('summary: passed > total(谎报)');
72
- if (passed + failed !== total) errors.push('summary: passed+failed (' + (passed + failed) + ') != total (' + total + ')');
73
- }
74
- }
75
- if (!Array.isArray(raw.failedItems)) errors.push('failedItems: required array');
76
- return errors;
77
- }
78
-
79
- var HARD_RE = /(passed > total|passed\+failed|non-negative integer required)/;
80
-
81
- /**
82
- * 校验 fenced block 解析出的 raw 对象。
83
- * @param {object|null} raw parseCheckResult 的产物
84
- * @returns {{ valid: boolean, hard: boolean, errors: string[] }}
85
- * hard=true 表示数值谎报(调用方应硬改判 failed)
86
- */
87
- function validateCheckResult(raw) {
88
- var errors;
89
- var ajvValidate = loadAjvValidator();
90
- if (ajvValidate) {
91
- var ok = ajvValidate(raw);
92
- errors = ok ? [] : (ajvValidate.errors || []).map(function (e) {
93
- return (e.instancePath || e.dataPath || '') + ' ' + e.message;
94
- });
95
- // ajv 通过(结构合法)后仍需跑数值一致性检查——schema 里 minimum 拦负数,
96
- // 但「passed+failed != total」「passed > total」是跨字段语义,schema 表达不了
97
- if (ok) {
98
- var semantic = builtinSemanticOnly(raw);
99
- if (semantic.length > 0) {
100
- return { valid: false, hard: true, errors: semantic };
101
- }
102
- }
103
- } else {
104
- errors = builtinValidate(raw);
105
- }
106
-
107
- var hard = errors.some(function (e) { return HARD_RE.test(e); });
108
- return { valid: errors.length === 0, hard: hard, errors: errors };
109
- }
110
-
111
- /** 仅跨字段语义检查(供 ajv 主路径补充调用) */
112
- function builtinSemanticOnly(raw) {
113
- var errors = [];
114
- var s = raw && raw.summary;
115
- if (s && typeof s === 'object' &&
116
- typeof s.total === 'number' && typeof s.passed === 'number' && typeof s.failed === 'number') {
117
- if (s.passed > s.total) errors.push('summary: passed > total(谎报)');
118
- if (s.passed + s.failed !== s.total) {
119
- errors.push('summary: passed+failed (' + (s.passed + s.failed) + ') != total (' + s.total + ')');
120
- }
121
- }
122
- return errors;
123
- }
124
-
125
- module.exports = {
126
- validateCheckResult: validateCheckResult,
127
- builtinValidate: builtinValidate,
128
- builtinSemanticOnly: builtinSemanticOnly,
129
- _loadAjvValidator: loadAjvValidator,
130
- _resetValidatorCache: _resetValidatorCache,
131
- };
@@ -1,81 +0,0 @@
1
- 'use strict';
2
-
3
- // ---------------------------------------------------------------------------
4
- // 上下文窗口分档(Phase B-2)
5
- // ---------------------------------------------------------------------------
6
- // 原框架 context_window.max_tokens 硬默认 200000,与 2026 年模型窗口现状脱节
7
- // (DeepSeek V4-Pro 官方 1M;其余 provider 档位以官方文档为准)。分档只在
8
- // loop 运行时才有意义——build 期不知道用户会用哪个 provider。
9
- //
10
- // 解析优先级:
11
- // 1. provider profile 显式声明 `context_window_tokens`(harness-config.yaml
12
- // 的 loop.providers 段,一份 profile 一档)
13
- // 2. 内置档位表按模型名前缀匹配(最长前缀优先)
14
- // 3. 保守默认 200000(unknown / 未声明 / 旧模型)
15
- //
16
- // 本模块只做「解析 + 告知」:把窗口预算交给 executor prompt(会话内分块读取
17
- // 策略用对预算),不做 prompt 裁剪——裁剪属独立功能,不混入。
18
- // ---------------------------------------------------------------------------
19
-
20
- // 保守默认:未知 provider / 未声明 / 档位表未命中
21
- var DEFAULT_CONTEXT_WINDOW = 200000;
22
-
23
- // 内置档位表:模型名前缀 → 窗口 tokens(最长前缀优先)。
24
- // 仅收录有官方公开依据的档位;新 provider 档位优先用 profile.context_window_tokens
25
- // 显式声明,不要凭猜测改本表。
26
- var TIERS = Object.freeze([
27
- Object.freeze({ prefix: 'deepseek-v4', tokens: 1000000 }), // DeepSeek V4-Pro 官方 1M
28
- ]);
29
-
30
- /**
31
- * 按模型名前缀匹配档位(最长前缀优先)。
32
- * @param {string|null} model 生效模型名(如 "deepseek-v4-pro"、"glm-5.2")
33
- * @returns {number|null} 命中的窗口 tokens;未命中返回 null(走默认)
34
- */
35
- function matchTiers(model) {
36
- if (!model || typeof model !== 'string') return null;
37
- var lower = model.toLowerCase();
38
- var best = null;
39
- var bestLen = -1;
40
- for (var i = 0; i < TIERS.length; i++) {
41
- var tier = TIERS[i];
42
- if (lower.indexOf(tier.prefix) === 0 && tier.prefix.length > bestLen) {
43
- best = tier.tokens;
44
- bestLen = tier.prefix.length;
45
- }
46
- }
47
- return best;
48
- }
49
-
50
- /**
51
- * 解析当前生效模型的上下文窗口预算。
52
- * @param {object} [opts]
53
- * @param {string|null} [opts.model] 生效模型名
54
- * @param {object|null} [opts.profile] provider-resolver 匹配的 provider 规则对象;
55
- * 可选字段 `context_window_tokens`(显式档位,最高优先)
56
- * @returns {{ tokens: number, source: 'profile'|'tiers'|'default', model: string|null }}
57
- * source 说明预算来源,供日志/测试断言
58
- */
59
- function resolveContextWindow(opts) {
60
- opts = opts || {};
61
- var model = opts.model || null;
62
- var profile = opts.profile && typeof opts.profile === 'object' ? opts.profile : null;
63
-
64
- if (profile && typeof profile.context_window_tokens === 'number' && profile.context_window_tokens > 0) {
65
- return { tokens: profile.context_window_tokens, source: 'profile', model: model };
66
- }
67
-
68
- var tierHit = matchTiers(model);
69
- if (tierHit !== null) {
70
- return { tokens: tierHit, source: 'tiers', model: model };
71
- }
72
-
73
- return { tokens: DEFAULT_CONTEXT_WINDOW, source: 'default', model: model };
74
- }
75
-
76
- module.exports = {
77
- resolveContextWindow: resolveContextWindow,
78
- matchTiers: matchTiers,
79
- TIERS: TIERS,
80
- DEFAULT_CONTEXT_WINDOW: DEFAULT_CONTEXT_WINDOW,
81
- };