doukui 0.6.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 (92) hide show
  1. package/README.en.md +85 -18
  2. package/README.md +32 -72
  3. package/bin/commands/help.js +2 -25
  4. package/bin/commands/plan-lint.js +105 -0
  5. package/bin/commands/verify.js +263 -0
  6. package/bin/doukui.js +3 -3
  7. package/package.json +2 -3
  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 +89 -0
  13. package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
  14. package/plugins/core/skill-agent-dispatcher/recovery-reference.md +132 -0
  15. package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
  16. package/plugins/core/skill-agent-dispatcher/skill.md +124 -796
  17. package/plugins/core/skill-agentic-loop/mirror-rules.md +95 -24
  18. package/plugins/core/skill-agentic-loop/plugin.json +2 -7
  19. package/plugins/core/skill-agentic-loop/skill.md +125 -354
  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-completion-report/skill.md +7 -1
  24. package/plugins/core/skill-doukui-plan/plugin.json +1 -1
  25. package/plugins/core/skill-doukui-plan/skill.md +24 -21
  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-task-creator/plugin.json +1 -1
  30. package/plugins/core/skill-task-creator/skill.md +1 -139
  31. package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
  32. package/plugins/plugin-registry.json +0 -48
  33. package/plugins/runtime/harness-build.js +5 -5
  34. package/plugins/runtime/plan-reader.js +54 -21
  35. package/plugins/runtime/resolve-plugin-path.js +2 -2
  36. package/templates/harness-config.yaml +0 -100
  37. package/bin/commands/loop-server.js +0 -357
  38. package/bin/commands/loop.js +0 -1508
  39. package/plugins/contracts/capabilities.js +0 -268
  40. package/plugins/contracts/checkresult-schema.json +0 -75
  41. package/plugins/core/provider-loop-engine/index.js +0 -1411
  42. package/plugins/core/provider-loop-engine/plugin.json +0 -15
  43. package/plugins/core/provider-memory-store/index.js +0 -510
  44. package/plugins/core/provider-memory-store/plugin.json +0 -9
  45. package/plugins/core/provider-state-store/index.js +0 -244
  46. package/plugins/core/provider-state-store/plugin.json +0 -9
  47. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
  48. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
  49. package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
  50. package/plugins/core/provider-watchdog/index.js +0 -151
  51. package/plugins/core/provider-watchdog/plugin.json +0 -13
  52. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
  53. package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
  54. package/plugins/core/skill-watchdog-manager/skill.md +0 -143
  55. package/plugins/core/validator-doc-sync/index.js +0 -248
  56. package/plugins/core/validator-doc-sync/plugin.json +0 -12
  57. package/plugins/core/validator-work-package/index.js +0 -300
  58. package/plugins/core/validator-work-package/plugin.json +0 -12
  59. package/plugins/runtime/audit-logger.js +0 -311
  60. package/plugins/runtime/build-cli.js +0 -89
  61. package/plugins/runtime/checkresult-validator.js +0 -131
  62. package/plugins/runtime/context-window.js +0 -81
  63. package/plugins/runtime/event-bus.js +0 -207
  64. package/plugins/runtime/executor-claude.js +0 -604
  65. package/plugins/runtime/executor-default.js +0 -448
  66. package/plugins/runtime/executor-local.js +0 -178
  67. package/plugins/runtime/executor-sdk.js +0 -415
  68. package/plugins/runtime/hook-dispatcher.js +0 -315
  69. package/plugins/runtime/loop-actuator.js +0 -292
  70. package/plugins/runtime/loop-coordinator.js +0 -347
  71. package/plugins/runtime/loop-defaults.js +0 -29
  72. package/plugins/runtime/loop-dispatch-batch.js +0 -351
  73. package/plugins/runtime/loop-executor.js +0 -120
  74. package/plugins/runtime/loop-report.js +0 -395
  75. package/plugins/runtime/loop-server-core.js +0 -750
  76. package/plugins/runtime/loop-snapshot.js +0 -581
  77. package/plugins/runtime/loop-trace.js +0 -242
  78. package/plugins/runtime/loop-worktree.js +0 -404
  79. package/plugins/runtime/multi-window-coordinator.js +0 -560
  80. package/plugins/runtime/objective-verifier.js +0 -136
  81. package/plugins/runtime/plan-lint.js +0 -106
  82. package/plugins/runtime/plugin-loader.js +0 -798
  83. package/plugins/runtime/plugin-trust.js +0 -182
  84. package/plugins/runtime/provider-failover.js +0 -114
  85. package/plugins/runtime/provider-resolver.js +0 -342
  86. package/plugins/runtime/reflection-evaluator.js +0 -545
  87. package/plugins/runtime/sandbox-context.js +0 -235
  88. package/plugins/runtime/sandbox-manager.js +0 -609
  89. package/plugins/runtime/sandbox-worker.js +0 -215
  90. package/plugins/runtime/self-rescue-ladder.js +0 -51
  91. package/plugins/runtime/text-tokenize.js +0 -25
  92. package/plugins/runtime/validator-pipeline.js +0 -475
@@ -1,215 +0,0 @@
1
- /**
2
- * sandbox-worker.js - Worker Thread script for sandboxed plugin execution
3
- *
4
- * This script runs inside a Worker Thread and:
5
- * 1. Receives plugin metadata via workerData
6
- * 2. Creates a SandboxContext proxy for the plugin
7
- * 3. Loads the plugin module
8
- * 4. Calls plugin.onActivate(sandboxContext)
9
- * 5. Forwards all context method calls via postMessage RPC to the main thread
10
- *
11
- * This file is loaded by SandboxManager as the Worker entry point.
12
- *
13
- * @module sandbox-worker
14
- */
15
-
16
- 'use strict';
17
-
18
- var workerThreads = require('worker_threads');
19
- var parentPort = workerThreads.parentPort;
20
- var workerData = workerThreads.workerData;
21
-
22
- if (!workerData || !workerData.pluginName) {
23
- parentPort.postMessage({
24
- type: 'activation-error',
25
- error: 'Missing workerData.pluginName',
26
- });
27
- // Exit with error
28
- process.exit(1);
29
- }
30
-
31
- var pluginName = workerData.pluginName;
32
- var pluginPath = workerData.pluginPath;
33
- var sourceType = workerData.sourceType;
34
- var declaredCapabilities = workerData.capabilities || {};
35
-
36
- // ---------------------------------------------------------------------------
37
- // SandboxContext - RPC proxy layer (runs inside worker)
38
- // ---------------------------------------------------------------------------
39
-
40
- /**
41
- * SandboxContext provides a PluginContext-compatible interface inside the worker.
42
- * All method calls are forwarded to the main thread via postMessage RPC.
43
- *
44
- * @internal 此函数仅在 Worker Thread 内部使用
45
- * @param {string} name - plugin name
46
- * @param {MessagePort} port - parent port for communication
47
- */
48
- function SandboxContext(name, port) {
49
- this.pluginName = name;
50
- this._port = port;
51
- this._rpcId = 0;
52
-
53
- // Proxy eventBus: emit only (subscribe requires main-thread coordination)
54
- this.eventBus = {
55
- emit: function (event, data) {
56
- return this._rpc('eventBus.emit', [event, data]);
57
- }.bind(this),
58
- };
59
-
60
- // Proxy stateStore
61
- this.stateStore = {
62
- get: function (key) {
63
- return this._rpc('stateStore.get', [key]);
64
- }.bind(this),
65
- set: function (key, value) {
66
- return this._rpc('stateStore.set', [key, value]);
67
- }.bind(this),
68
- delete: function (key) {
69
- return this._rpc('stateStore.delete', [key]);
70
- }.bind(this),
71
- };
72
-
73
- // Proxy logger
74
- this.logger = {
75
- info: function (msg) {
76
- return this._rpc('logger.info', [msg]);
77
- }.bind(this),
78
- warn: function (msg) {
79
- return this._rpc('logger.warn', [msg]);
80
- }.bind(this),
81
- error: function (msg) {
82
- return this._rpc('logger.error', [msg]);
83
- }.bind(this),
84
- };
85
-
86
- // config (read-only)
87
- this.config = {
88
- get: function (key) {
89
- return this._rpc('config.get', [key]);
90
- }.bind(this),
91
- };
92
-
93
- // Provider cache
94
- this._providerCache = {};
95
- }
96
-
97
- /**
98
- * Get a provider by name (via RPC to main thread).
99
- *
100
- * @internal
101
- * @param {string} name - provider name
102
- * @returns {Promise<object>}
103
- */
104
- SandboxContext.prototype.getProvider = function (name) {
105
- if (this._providerCache[name]) {
106
- return Promise.resolve(this._providerCache[name]);
107
- }
108
-
109
- var self = this;
110
- return this._rpc('getProvider', [name]).then(function (provider) {
111
- self._providerCache[name] = provider;
112
- return provider;
113
- });
114
- };
115
-
116
- /**
117
- * Get another plugin by name (not supported in sandbox — returns undefined).
118
- *
119
- * @param {string} _name
120
- * @returns {undefined}
121
- */
122
- SandboxContext.prototype.getPlugin = function (_name) {
123
- // Cross-plugin access not supported in sandbox for security
124
- return undefined;
125
- };
126
-
127
- /**
128
- * Send an RPC request to the main thread and wait for the response.
129
- *
130
- * @param {string} method - method name
131
- * @param {Array} args - arguments (must be serializable)
132
- * @returns {Promise<any>}
133
- */
134
- SandboxContext.prototype._rpc = function (method, args) {
135
- var id = ++this._rpcId;
136
- var port = this._port;
137
- var timeout = 30000;
138
-
139
- return new Promise(function (resolve, reject) {
140
- var timer = setTimeout(function () {
141
- port.off('message', handler);
142
- reject(new Error('RPC timeout for ' + method + ' after ' + timeout + 'ms'));
143
- }, timeout);
144
-
145
- var handler = function (msg) {
146
- if (msg.type === 'rpc-response' && msg.id === id) {
147
- clearTimeout(timer);
148
- port.off('message', handler);
149
- if (msg.error) {
150
- reject(new Error(msg.error));
151
- } else {
152
- resolve(msg.result);
153
- }
154
- }
155
- };
156
-
157
- port.on('message', handler);
158
- port.postMessage({
159
- type: 'rpc-request',
160
- id: id,
161
- method: method,
162
- args: args,
163
- });
164
- });
165
- };
166
-
167
- // ---------------------------------------------------------------------------
168
- // Load and activate the plugin
169
- // ---------------------------------------------------------------------------
170
-
171
- try {
172
- // Require the plugin module
173
- var indexJsPath = require('path').resolve(pluginPath, 'index.js');
174
- var PluginClass = require(indexJsPath);
175
-
176
- if (typeof PluginClass !== 'function') {
177
- throw new Error('Plugin "' + pluginName + '" does not export a constructor function');
178
- }
179
-
180
- var pluginInstance = new PluginClass();
181
- var context = new SandboxContext(pluginName, parentPort);
182
-
183
- // Call onActivate
184
- if (typeof pluginInstance.onActivate === 'function') {
185
- var activateResult = pluginInstance.onActivate(context);
186
-
187
- // Handle async onActivate
188
- if (activateResult && typeof activateResult.then === 'function') {
189
- activateResult.then(function () {
190
- parentPort.postMessage({ type: 'activated' });
191
- }).catch(function (err) {
192
- parentPort.postMessage({
193
- type: 'activation-error',
194
- error: err.message,
195
- });
196
- });
197
- } else {
198
- parentPort.postMessage({ type: 'activated' });
199
- }
200
- } else {
201
- parentPort.postMessage({ type: 'activated' });
202
- }
203
- } catch (err) {
204
- parentPort.postMessage({
205
- type: 'activation-error',
206
- error: 'Failed to load plugin "' + pluginName + '": ' + err.message,
207
- });
208
- }
209
-
210
- // Handle terminate signal from main thread
211
- parentPort.on('message', function (msg) {
212
- if (msg.type === 'terminate') {
213
- process.exit(0);
214
- }
215
- });
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- // ---------------------------------------------------------------------------
4
- // Self-Rescue Ladder(v0.3.1 T7 抽取纯函数;v0.4.0 A1 补全北极星终态四级梯)
5
- // ---------------------------------------------------------------------------
6
- // 深审维度 1:梯子优先级逻辑(provider 优先于 model、每级一次、穷尽返回 null)
7
- // 原内嵌在 driver execute 闭包内无法直测。抽出纯函数 + 单测锁定语义。
8
- //
9
- // 北极星 1 终态语义:diverged/timeout 不是「停下来等人」,先穷尽自救链
10
- // ① switch_provider(换 provider)→ ② switch_model(换模型)
11
- // → ③ retry_resplit(纯重置续跑,下轮 engine 自选 retry/resplit)
12
- // → 梯子穷尽 → 降级交付(loop-report.generateDegradedDeliveryReport,
13
- // 已完成 WP 照常交付 + 未完成项交接明细,最后才升级人介入)。
14
- // ---------------------------------------------------------------------------
15
-
16
- /**
17
- * 找下一级可用的自救动作。
18
- * @param {string} verdict 'diverged'|'timeout'(其它 verdict 不自救)
19
- * @param {object} cfg { enabled, maxSwitches, modelFallback }
20
- * @param {string[]} used 已用级别(顺序即尝试序)
21
- * @param {object} failoverCfg { fallbackSettings, fallbackFileExists }(WP-D3 预解析产物)
22
- * @returns {{ type: string }|null} null = 梯子穷尽/自救停用
23
- */
24
- function planSelfRescue(verdict, cfg, used, failoverCfg) {
25
- if (verdict !== 'diverged' && verdict !== 'timeout') return null;
26
- cfg = cfg || {};
27
- if (cfg.enabled === false) return null;
28
- used = Array.isArray(used) ? used : [];
29
- if (used.length >= (cfg.maxSwitches || 0)) return null;
30
- failoverCfg = failoverCfg || {};
31
-
32
- // 优先级 ①:换 provider(需 fallback settings 可读——复用 WP-D3 预解析)
33
- if (used.indexOf('switch_provider') === -1 &&
34
- failoverCfg.fallbackSettings && failoverCfg.fallbackFileExists) {
35
- return { type: 'switch_provider' };
36
- }
37
- // 优先级 ②:换模型(需显式配置备用模型档)
38
- if (used.indexOf('switch_model') === -1 && cfg.modelFallback) {
39
- return { type: 'switch_model' };
40
- }
41
- // 优先级 ③(v0.4.0 A1):纯重置续跑(零配置可用——多数用户没配 ①② 的前置,
42
- // 此级保证终态前至少多一次自救机会)。语义:重置发散计数 + 追加预算,
43
- // 下轮 engine Think 基于 lastChecklist 自然选择 retry(带 failingDrivers)
44
- // 或 resplit(拆当前失败 WP)策略——不自作主张指定策略,决策权留给 engine。
45
- if (used.indexOf('retry_resplit') === -1) {
46
- return { type: 'retry_resplit' };
47
- }
48
- return null;
49
- }
50
-
51
- module.exports = { planSelfRescue: planSelfRescue };
@@ -1,25 +0,0 @@
1
- 'use strict';
2
-
3
- // ---------------------------------------------------------------------------
4
- // 共享分词(WP-S4 从 provider-memory-store._tokenize 提取)
5
- // ---------------------------------------------------------------------------
6
- // 中文按字符 bigram(无词典依赖),拉丁/数字按词。两个消费方:
7
- // - provider-memory-store.recall(记忆召回打分)
8
- // - executor-claude buildPrompt 的精读 retry(失败项 ↔ 文档段落关联打分)
9
- // ---------------------------------------------------------------------------
10
-
11
- /**
12
- * 分词:拉丁词(小写)+ 中文字符 bigram。
13
- * @param {string} text
14
- * @returns {string[]}
15
- */
16
- function tokenize(text) {
17
- var tokens = [];
18
- var latin = String(text || '').toLowerCase().match(/[a-z0-9_]+/g) || [];
19
- for (var i = 0; i < latin.length; i++) tokens.push(latin[i]);
20
- var cjk = String(text || '').match(/[\u4e00-\u9fff]/g) || [];
21
- for (var j = 0; j < cjk.length - 1; j++) tokens.push(cjk[j] + cjk[j + 1]);
22
- return tokens;
23
- }
24
-
25
- module.exports = { tokenize: tokenize };