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.
- package/README.en.md +85 -18
- package/README.md +32 -72
- package/bin/commands/help.js +2 -25
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +3 -3
- package/package.json +2 -3
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +64 -15
- package/plugins/core/hook-skill-gate/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
- package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +89 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +132 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +124 -796
- package/plugins/core/skill-agentic-loop/mirror-rules.md +95 -24
- package/plugins/core/skill-agentic-loop/plugin.json +2 -7
- package/plugins/core/skill-agentic-loop/skill.md +125 -354
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-completion-report/skill.md +7 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +24 -21
- package/plugins/core/skill-experience-logger/plugin.json +1 -1
- package/plugins/core/skill-human-checkpoint/skill.md +1 -0
- package/plugins/core/skill-split-work-package/plugin.json +1 -1
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +1 -139
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -48
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +54 -21
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/templates/harness-config.yaml +0 -100
- package/bin/commands/loop-server.js +0 -357
- package/bin/commands/loop.js +0 -1508
- package/plugins/contracts/capabilities.js +0 -268
- package/plugins/contracts/checkresult-schema.json +0 -75
- package/plugins/core/provider-loop-engine/index.js +0 -1411
- package/plugins/core/provider-loop-engine/plugin.json +0 -15
- package/plugins/core/provider-memory-store/index.js +0 -510
- package/plugins/core/provider-memory-store/plugin.json +0 -9
- package/plugins/core/provider-state-store/index.js +0 -244
- package/plugins/core/provider-state-store/plugin.json +0 -9
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
- package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
- package/plugins/core/provider-watchdog/index.js +0 -151
- package/plugins/core/provider-watchdog/plugin.json +0 -13
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
- package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
- package/plugins/core/skill-watchdog-manager/skill.md +0 -143
- package/plugins/core/validator-doc-sync/index.js +0 -248
- package/plugins/core/validator-doc-sync/plugin.json +0 -12
- package/plugins/core/validator-work-package/index.js +0 -300
- package/plugins/core/validator-work-package/plugin.json +0 -12
- package/plugins/runtime/audit-logger.js +0 -311
- package/plugins/runtime/build-cli.js +0 -89
- package/plugins/runtime/checkresult-validator.js +0 -131
- package/plugins/runtime/context-window.js +0 -81
- package/plugins/runtime/event-bus.js +0 -207
- package/plugins/runtime/executor-claude.js +0 -604
- package/plugins/runtime/executor-default.js +0 -448
- package/plugins/runtime/executor-local.js +0 -178
- package/plugins/runtime/executor-sdk.js +0 -415
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/loop-actuator.js +0 -292
- package/plugins/runtime/loop-coordinator.js +0 -347
- package/plugins/runtime/loop-defaults.js +0 -29
- package/plugins/runtime/loop-dispatch-batch.js +0 -351
- package/plugins/runtime/loop-executor.js +0 -120
- package/plugins/runtime/loop-report.js +0 -395
- package/plugins/runtime/loop-server-core.js +0 -750
- package/plugins/runtime/loop-snapshot.js +0 -581
- package/plugins/runtime/loop-trace.js +0 -242
- package/plugins/runtime/loop-worktree.js +0 -404
- package/plugins/runtime/multi-window-coordinator.js +0 -560
- package/plugins/runtime/objective-verifier.js +0 -136
- package/plugins/runtime/plan-lint.js +0 -106
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- package/plugins/runtime/provider-failover.js +0 -114
- package/plugins/runtime/provider-resolver.js +0 -342
- package/plugins/runtime/reflection-evaluator.js +0 -545
- package/plugins/runtime/sandbox-context.js +0 -235
- package/plugins/runtime/sandbox-manager.js +0 -609
- package/plugins/runtime/sandbox-worker.js +0 -215
- package/plugins/runtime/self-rescue-ladder.js +0 -51
- package/plugins/runtime/text-tokenize.js +0 -25
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* verify command - Batch-run the `[verify: ...]` commands of a plan work unit's
|
|
5
|
+
* checklist (plan-reader contract) and emit a CheckResult
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var childProcess = require('child_process');
|
|
10
|
+
var planReader = require('../../plugins/runtime/plan-reader');
|
|
11
|
+
|
|
12
|
+
var DEFAULT_TIMEOUT_SEC = 600;
|
|
13
|
+
var MAX_TIMEOUT_SEC = 1800;
|
|
14
|
+
var MAX_BUFFER = 16 * 1024 * 1024;
|
|
15
|
+
var OUTPUT_TAIL_LEN = 600;
|
|
16
|
+
var USAGE = 'doukui verify <plan路径> --wp WP-NNN|all [--timeout 秒] [--json]';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tail of captured stdout/stderr (truncated, for retry positioning).
|
|
20
|
+
*/
|
|
21
|
+
function tailOf(stdout, stderr) {
|
|
22
|
+
var s = (String(stdout || '') + '\n' + String(stderr || '')).trim();
|
|
23
|
+
return s.length > OUTPUT_TAIL_LEN ? '…' + s.slice(-OUTPUT_TAIL_LEN) : s;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Kill the whole process tree on timeout. On Windows the shell must still be
|
|
28
|
+
* alive for `taskkill /T` to trace its children (once the shell dies they are
|
|
29
|
+
* orphaned), so the tree is killed here instead of relying on exec's own
|
|
30
|
+
* timeout. POSIX: only the shell itself.
|
|
31
|
+
*/
|
|
32
|
+
function defaultKillTree(child) {
|
|
33
|
+
if (!child || !child.pid) return;
|
|
34
|
+
if (process.platform === 'win32') {
|
|
35
|
+
childProcess.spawnSync('taskkill', ['/T', '/F', '/PID', String(child.pid)], { windowsHide: true });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
try { child.kill('SIGKILL'); } catch (e) { /* already gone */ }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run one command (cwd = project root, default shell).
|
|
43
|
+
* done({ exitCode, passed, reason, outputTail })
|
|
44
|
+
* reason: null | 'exit=N' | 'timeout' | '命令不可执行: <msg>'
|
|
45
|
+
*/
|
|
46
|
+
function runCommand(deps, command, cwd, timeoutMs, done) {
|
|
47
|
+
var timedOut = false;
|
|
48
|
+
var timer = null;
|
|
49
|
+
function finish(exitCode, reason, stdout, stderr) {
|
|
50
|
+
done({
|
|
51
|
+
exitCode: exitCode,
|
|
52
|
+
passed: reason === null,
|
|
53
|
+
reason: reason,
|
|
54
|
+
outputTail: reason === null ? undefined : tailOf(stdout, stderr),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
var child;
|
|
58
|
+
try {
|
|
59
|
+
child = deps.exec(command, { cwd: cwd, maxBuffer: MAX_BUFFER, windowsHide: true }, function (err, stdout, stderr) {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
if (timedOut) { finish(null, 'timeout', stdout, stderr); return; }
|
|
62
|
+
// spawn 失败(shell 起不来 / ENOENT / EACCES):err.code 是字符串而非退出码
|
|
63
|
+
if (err && typeof err.code === 'string') {
|
|
64
|
+
finish(null, '命令不可执行: ' + (err.message || err), stdout, stderr);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
var code = err ? (typeof err.code === 'number' ? err.code : 1) : 0;
|
|
68
|
+
finish(code, code === 0 ? null : 'exit=' + code, stdout, stderr);
|
|
69
|
+
});
|
|
70
|
+
} catch (e) {
|
|
71
|
+
finish(null, '命令不可执行: ' + (e && e.message ? e.message : e), '', '');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
timer = setTimeout(function () {
|
|
75
|
+
timedOut = true;
|
|
76
|
+
deps.killTree(child);
|
|
77
|
+
}, timeoutMs);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Serially run every verify item of one work unit. done(checkResult).
|
|
82
|
+
*/
|
|
83
|
+
function verifyWorkPackage(wp, deps, done) {
|
|
84
|
+
var checklist = wp.checklist || [];
|
|
85
|
+
var verifyItems = [];
|
|
86
|
+
var manualItems = [];
|
|
87
|
+
for (var i = 0; i < checklist.length; i++) {
|
|
88
|
+
var it = checklist[i];
|
|
89
|
+
if (it.verify && it.verify.command) verifyItems.push(it);
|
|
90
|
+
else manualItems.push({ id: it.id, item: it.item });
|
|
91
|
+
}
|
|
92
|
+
var results = [];
|
|
93
|
+
var failedItems = [];
|
|
94
|
+
(function next() {
|
|
95
|
+
if (results.length >= verifyItems.length) {
|
|
96
|
+
var passCount = results.filter(function (r) { return r.passed; }).length;
|
|
97
|
+
var failCount = results.length - passCount;
|
|
98
|
+
done({
|
|
99
|
+
wpId: wp.wpId,
|
|
100
|
+
passed: failCount === 0 && verifyItems.length > 0,
|
|
101
|
+
summary: { total: checklist.length, passed: passCount, failed: failCount, manual: manualItems.length },
|
|
102
|
+
verifyResults: results,
|
|
103
|
+
failedItems: failedItems,
|
|
104
|
+
manualItems: manualItems,
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
var item = verifyItems[results.length];
|
|
109
|
+
runCommand(deps, item.verify.command, deps.cwd, deps.timeoutMs, function (r) {
|
|
110
|
+
var entry = { id: item.id, item: item.item, command: item.verify.command, exitCode: r.exitCode, passed: r.passed };
|
|
111
|
+
if (!r.passed) {
|
|
112
|
+
entry.outputTail = r.outputTail;
|
|
113
|
+
failedItems.push({ category: item.category, id: item.id, item: item.item, reason: r.reason });
|
|
114
|
+
}
|
|
115
|
+
results.push(entry);
|
|
116
|
+
if (deps.onResult) deps.onResult(entry, r.reason);
|
|
117
|
+
next();
|
|
118
|
+
});
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 0 = every verify item passed; 1 = any failure; 2 = no verify item in scope.
|
|
124
|
+
*/
|
|
125
|
+
function exitCodeOf(result) {
|
|
126
|
+
if (result.verifyResults.length === 0) return 2;
|
|
127
|
+
return result.failedItems.length > 0 ? 1 : 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function printEntry(ctx, entry, reason) {
|
|
131
|
+
var mark = entry.passed ? ctx.colorize('PASS', 'green') : ctx.colorize('FAIL', 'red');
|
|
132
|
+
console.log(' ' + mark + ' ' + entry.id + ' exit=' + (entry.exitCode === null ? '-' : entry.exitCode) +
|
|
133
|
+
' ' + entry.item + (entry.passed ? '' : ctx.colorize(' ← ' + reason, 'red')));
|
|
134
|
+
if (entry.outputTail) {
|
|
135
|
+
console.log(ctx.colorize(entry.outputTail.split('\n').map(function (l) { return ' ' + l; }).join('\n'), 'dim'));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function printSummary(ctx, r) {
|
|
140
|
+
var s = r.summary;
|
|
141
|
+
var head = '结论:' + r.wpId + ' verify ' + s.passed + '/' + (s.passed + s.failed);
|
|
142
|
+
if (r.verifyResults.length === 0) {
|
|
143
|
+
console.log(ctx.colorize(head + ' 无 verify 项,' + s.manual + ' 项全 manual,需 LLM 判(exit 2)', 'yellow'));
|
|
144
|
+
} else if (r.failedItems.length > 0) {
|
|
145
|
+
console.log(ctx.colorize(head + ' 失败 ' + s.failed + ' 项(exit 1)', 'red'));
|
|
146
|
+
} else {
|
|
147
|
+
console.log(ctx.colorize(head + ' 全过(exit 0)', 'green') +
|
|
148
|
+
(s.manual > 0 ? ctx.colorize(' manual ' + s.manual + ' 项待 Lead 判定', 'dim') : ''));
|
|
149
|
+
}
|
|
150
|
+
for (var i = 0; i < r.manualItems.length; i++) {
|
|
151
|
+
console.log(ctx.colorize(' MANUAL ' + r.manualItems[i].id + ' ' + r.manualItems[i].item, 'dim'));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function parseArgs(argv) {
|
|
156
|
+
var o = { planPath: null, wp: null, timeoutSec: DEFAULT_TIMEOUT_SEC, json: false, usageError: null };
|
|
157
|
+
for (var i = 0; i < argv.length && !o.usageError; i++) {
|
|
158
|
+
var a = argv[i];
|
|
159
|
+
if (a === '--json') o.json = true;
|
|
160
|
+
else if (a === '--wp' || a === '--timeout') {
|
|
161
|
+
var v = argv[i + 1];
|
|
162
|
+
if (v === undefined || v.indexOf('--') === 0) o.usageError = a + ' 缺少参数';
|
|
163
|
+
else if (a === '--wp') o.wp = v;
|
|
164
|
+
else o.timeoutSec = parseFloat(v);
|
|
165
|
+
i += 1;
|
|
166
|
+
} else if (a.indexOf('--wp=') === 0) o.wp = a.slice(5);
|
|
167
|
+
else if (a.indexOf('--timeout=') === 0) o.timeoutSec = parseFloat(a.slice(10));
|
|
168
|
+
else if (a.indexOf('--') === 0) o.usageError = '未知参数 ' + a;
|
|
169
|
+
else if (o.planPath === null) o.planPath = a;
|
|
170
|
+
else o.usageError = '多余参数 ' + a;
|
|
171
|
+
}
|
|
172
|
+
if (!o.usageError && !o.planPath) o.usageError = '缺少 plan 路径';
|
|
173
|
+
if (!o.usageError && !o.wp) o.usageError = '缺少 --wp WP-NNN|all';
|
|
174
|
+
if (!o.usageError && !(o.timeoutSec > 0)) o.usageError = '--timeout 需为正数秒';
|
|
175
|
+
if (o.timeoutSec > MAX_TIMEOUT_SEC) o.timeoutSec = MAX_TIMEOUT_SEC;
|
|
176
|
+
return o;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Command factory. deps.exec / deps.killTree are injectable (tests use fakes);
|
|
181
|
+
* defaults are child_process.exec and the taskkill tree-kill above.
|
|
182
|
+
*/
|
|
183
|
+
function createVerifyCommand(deps) {
|
|
184
|
+
deps = deps || {};
|
|
185
|
+
return {
|
|
186
|
+
name: 'verify',
|
|
187
|
+
description: 'Run a plan work unit\'s [verify:] commands and emit CheckResult',
|
|
188
|
+
/**
|
|
189
|
+
* usage: doukui verify <plan路径> --wp WP-NNN|all [--timeout 秒] [--json]
|
|
190
|
+
* exit 0 = all verify items passed; 1 = any failure (usage/parse errors too);
|
|
191
|
+
* 2 = no verify item in scope (all manual, needs LLM judgment)
|
|
192
|
+
* @public
|
|
193
|
+
* @param {object} ctx - CLI context object
|
|
194
|
+
* @returns {Promise<void>}
|
|
195
|
+
*/
|
|
196
|
+
execute: function (ctx) {
|
|
197
|
+
var opts = parseArgs(ctx.argv || []);
|
|
198
|
+
var fail = function (msg) {
|
|
199
|
+
console.error(ctx.colorize('Error: ' + msg, 'red'));
|
|
200
|
+
ctx.exit(1);
|
|
201
|
+
};
|
|
202
|
+
if (opts.usageError) return fail(opts.usageError + '\nUsage: ' + USAGE);
|
|
203
|
+
|
|
204
|
+
var projectRoot = ctx.targetRoot;
|
|
205
|
+
var parsed = planReader.parsePlanToGoal({
|
|
206
|
+
planFilePath: opts.planPath,
|
|
207
|
+
projectRoot: projectRoot,
|
|
208
|
+
throwOnCycle: false,
|
|
209
|
+
});
|
|
210
|
+
if (parsed.error) return fail(parsed.error);
|
|
211
|
+
|
|
212
|
+
var all = opts.wp.toLowerCase() === 'all';
|
|
213
|
+
var targets = parsed.workPackages;
|
|
214
|
+
if (!all) {
|
|
215
|
+
var wanted = opts.wp.toUpperCase();
|
|
216
|
+
targets = targets.filter(function (wp) { return wp.wpId.toUpperCase() === wanted; });
|
|
217
|
+
if (targets.length === 0) {
|
|
218
|
+
return fail('wp-not-found: ' + opts.wp + '(可用: ' + parsed.goal.wpIds.join(', ') + ')');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
var runDeps = {
|
|
223
|
+
cwd: projectRoot,
|
|
224
|
+
timeoutMs: Math.round(opts.timeoutSec * 1000),
|
|
225
|
+
exec: deps.exec || childProcess.exec,
|
|
226
|
+
killTree: deps.killTree || defaultKillTree,
|
|
227
|
+
onResult: opts.json ? null : function (entry, reason) { printEntry(ctx, entry, reason); },
|
|
228
|
+
};
|
|
229
|
+
if (!opts.json) console.log(ctx.colorize('plan: ', 'dim') + parsed.planFilePath);
|
|
230
|
+
|
|
231
|
+
var results = [];
|
|
232
|
+
return new Promise(function (resolve) {
|
|
233
|
+
(function next() {
|
|
234
|
+
if (results.length >= targets.length) {
|
|
235
|
+
var codes = results.map(exitCodeOf);
|
|
236
|
+
var code = codes.indexOf(1) !== -1 ? 1 : (codes.indexOf(0) !== -1 ? 0 : 2);
|
|
237
|
+
if (opts.json) {
|
|
238
|
+
console.log(JSON.stringify(all ? results : results[0], null, 2));
|
|
239
|
+
} else {
|
|
240
|
+
for (var i = 0; i < results.length; i++) {
|
|
241
|
+
printSummary(ctx, results[i]);
|
|
242
|
+
console.log('```json:machine-readable\n' + JSON.stringify(results[i]) + '\n```');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
ctx.exit(code);
|
|
246
|
+
resolve();
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
var wp = targets[results.length];
|
|
250
|
+
if (!opts.json) {
|
|
251
|
+
var verifyCount = wp.checklist.filter(function (it) { return it.verify; }).length;
|
|
252
|
+
console.log(ctx.colorize(wp.wpId, 'green') + ' ' + wp.title +
|
|
253
|
+
ctx.colorize(' verify ' + verifyCount + '/' + wp.checklist.length + ' timeout ' + opts.timeoutSec + 's', 'dim'));
|
|
254
|
+
}
|
|
255
|
+
verifyWorkPackage(wp, runDeps, function (r) { results.push(r); next(); });
|
|
256
|
+
})();
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = createVerifyCommand();
|
|
263
|
+
module.exports.createVerifyCommand = createVerifyCommand;
|
package/bin/doukui.js
CHANGED
|
@@ -109,6 +109,8 @@ var commandModules = {
|
|
|
109
109
|
'build': 'build.js',
|
|
110
110
|
'validate': 'validate.js',
|
|
111
111
|
'validate-config': 'validate-config.js',
|
|
112
|
+
'plan-lint': 'plan-lint.js',
|
|
113
|
+
'verify': 'verify.js',
|
|
112
114
|
'init': 'init.js',
|
|
113
115
|
'migrate': 'migrate.js',
|
|
114
116
|
'status': 'status.js',
|
|
@@ -121,8 +123,6 @@ var commandModules = {
|
|
|
121
123
|
'help': 'help.js',
|
|
122
124
|
'install': 'install.js',
|
|
123
125
|
'team-cleanup': 'team-cleanup.js',
|
|
124
|
-
'loop': 'loop.js',
|
|
125
|
-
'loop-server': 'loop-server.js',
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
function loadCommand(cmdName) {
|
|
@@ -194,7 +194,7 @@ var context = createContext({
|
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
// #11:顶层错误兜底——命令可能同步抛错(如 team-cleanup 的非法输入),
|
|
197
|
-
// 也可能返回被 reject 的 Promise
|
|
197
|
+
// 也可能返回被 reject 的 Promise(异步命令)。
|
|
198
198
|
// 任一情况都给出干净的退出码 + 错误信息,而非裸露的 Node 堆栈/unhandledRejection。
|
|
199
199
|
function failCommand(err) {
|
|
200
200
|
var msg = err && err.message ? err.message : String(err);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doukui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Doukui (斗魁) -
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Doukui (斗魁) - in-session orchestration discipline pack for Claude Code: skills suite, plan-reader contract, multi-agent dispatch, agentic loop",
|
|
5
5
|
"bin": {
|
|
6
6
|
"doukui": "bin/doukui.js"
|
|
7
7
|
},
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
},
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"optionalDependencies": {
|
|
43
|
-
"@anthropic-ai/claude-agent-sdk": "^0.3.319",
|
|
44
43
|
"ajv": "^8.12.0"
|
|
45
44
|
},
|
|
46
45
|
"engines": {
|
|
@@ -257,7 +257,7 @@ function shouldSkipForDoubleTrigger(projectRoot) {
|
|
|
257
257
|
}
|
|
258
258
|
})();
|
|
259
259
|
|
|
260
|
-
// Export a no-op class for
|
|
260
|
+
// Export a no-op class for hook host compatibility
|
|
261
261
|
class SessionStartHook {
|
|
262
262
|
constructor() {
|
|
263
263
|
this.name = 'hook-session-start';
|
|
@@ -176,7 +176,6 @@ class SkillGateHook extends HookPlugin {
|
|
|
176
176
|
this.name = 'hook-skill-gate';
|
|
177
177
|
this.version = '1.0.0';
|
|
178
178
|
this.description = '统一技能门控 Hook';
|
|
179
|
-
this.dependencies = { providers: ['provider:state-store'] };
|
|
180
179
|
this.trigger = {
|
|
181
180
|
event: 'PreToolUse',
|
|
182
181
|
tools: ['Edit', 'Write'],
|
|
@@ -466,21 +465,23 @@ class SkillGateHook extends HookPlugin {
|
|
|
466
465
|
*
|
|
467
466
|
* @returns {boolean} true if this execution should be skipped
|
|
468
467
|
*/
|
|
469
|
-
_shouldSkipForDoubleTrigger() {
|
|
468
|
+
_shouldSkipForDoubleTrigger(context) {
|
|
469
|
+
// 防抖目标:global + project 双重注册对**同一事件**的毫秒级重复执行。
|
|
470
|
+
// 只按「同 event + 同 tool」且 1 秒内判重——旧版「任意 hook 5 秒」会吞掉
|
|
471
|
+
// 合法的相邻调用(如 PreToolUse(Edit) 后紧随的 PostToolUse(Skill))。
|
|
472
|
+
var key = ((context && context.event) || '') + ':' + ((context && context.tool) || '');
|
|
470
473
|
var markerPath = path.join(this._projectRoot, '.claude', '.hook-execution-marker');
|
|
471
474
|
|
|
472
|
-
// If another hook process is marked as active, skip
|
|
475
|
+
// If another hook process is marked as active for the same key, skip
|
|
473
476
|
if (fs.existsSync(markerPath)) {
|
|
474
477
|
try {
|
|
475
478
|
var marker = fs.readFileSync(markerPath, 'utf-8');
|
|
476
479
|
var markerData = JSON.parse(marker);
|
|
477
480
|
|
|
478
|
-
|
|
479
|
-
var now = Date.now();
|
|
480
|
-
if (markerData.timestamp && (now - markerData.timestamp) < 5000) {
|
|
481
|
+
if (markerData.key === key && markerData.timestamp && (Date.now() - markerData.timestamp) < 1000) {
|
|
481
482
|
return true;
|
|
482
483
|
}
|
|
483
|
-
// Stale marker — clean it up
|
|
484
|
+
// Stale / different-key marker — clean it up
|
|
484
485
|
try { fs.unlinkSync(markerPath); } catch (e) { /* ignore */ }
|
|
485
486
|
} catch (e) {
|
|
486
487
|
// Invalid marker, clean up
|
|
@@ -490,9 +491,10 @@ class SkillGateHook extends HookPlugin {
|
|
|
490
491
|
|
|
491
492
|
// Mark this hook as active
|
|
492
493
|
try {
|
|
494
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true });
|
|
493
495
|
fs.writeFileSync(
|
|
494
496
|
markerPath,
|
|
495
|
-
JSON.stringify({ timestamp: Date.now(), pid: process.pid }),
|
|
497
|
+
JSON.stringify({ timestamp: Date.now(), pid: process.pid, key: key }),
|
|
496
498
|
'utf-8'
|
|
497
499
|
);
|
|
498
500
|
} catch (e) {
|
|
@@ -583,6 +585,28 @@ function sanitizeObject(obj) {
|
|
|
583
585
|
return result;
|
|
584
586
|
}
|
|
585
587
|
|
|
588
|
+
/**
|
|
589
|
+
* Normalize a hook stdin payload across harness schemas.
|
|
590
|
+
*
|
|
591
|
+
* Claude Code passes `{ hook_event_name, tool_name, tool_input: {...} }` on
|
|
592
|
+
* stdin; the legacy/programmatic shape is `{ event, tool, skill }`. The gate
|
|
593
|
+
* previously read only the legacy keys, so in real sessions it never saw the
|
|
594
|
+
* tool/skill and the whole gate was inert. Unknown shapes fail open (empty
|
|
595
|
+
* strings) rather than crash.
|
|
596
|
+
* @param {object} raw - sanitized stdin payload
|
|
597
|
+
* @returns {{event: string, tool: string, skill: string, toolInput: object}}
|
|
598
|
+
*/
|
|
599
|
+
function normalizeHookContext(raw) {
|
|
600
|
+
raw = raw || {};
|
|
601
|
+
var toolInput = raw.tool_input || {};
|
|
602
|
+
return {
|
|
603
|
+
event: raw.hook_event_name || raw.event || '',
|
|
604
|
+
tool: raw.tool_name || raw.tool || '',
|
|
605
|
+
skill: toolInput.skill || toolInput.skillName || raw.skill || raw.skillName || '',
|
|
606
|
+
toolInput: toolInput,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
586
610
|
/**
|
|
587
611
|
* Main CLI function.
|
|
588
612
|
*/
|
|
@@ -591,21 +615,40 @@ function main() {
|
|
|
591
615
|
|
|
592
616
|
if (args.length === 0) {
|
|
593
617
|
console.error(
|
|
594
|
-
'Usage: node index.js --pre-tool | --post-skill\n' +
|
|
618
|
+
'Usage: node index.js --pre-tool | --post-skill | --reset\n' +
|
|
595
619
|
' --pre-tool Run PreToolUse check (reads context from stdin)\n' +
|
|
596
|
-
' --post-skill Run PostToolUse handler (reads context from stdin)'
|
|
620
|
+
' --post-skill Run PostToolUse handler (reads context from stdin)\n' +
|
|
621
|
+
' --reset Reset harness.state to idle (run after human-checkpoint approval)'
|
|
597
622
|
);
|
|
598
623
|
process.exit(1);
|
|
599
624
|
}
|
|
600
625
|
|
|
601
626
|
var mode = args[0];
|
|
602
|
-
if (mode !== '--pre-tool' && mode !== '--post-skill') {
|
|
627
|
+
if (mode !== '--pre-tool' && mode !== '--post-skill' && mode !== '--reset') {
|
|
603
628
|
console.error('Unknown mode: ' + mode);
|
|
604
|
-
console.error('Valid modes: --pre-tool, --post-skill');
|
|
629
|
+
console.error('Valid modes: --pre-tool, --post-skill, --reset');
|
|
605
630
|
process.exit(1);
|
|
606
631
|
}
|
|
607
632
|
|
|
608
|
-
|
|
633
|
+
if (mode === '--reset') {
|
|
634
|
+
var resetHook = new SkillGateHook();
|
|
635
|
+
resetHook
|
|
636
|
+
.onActivate(null)
|
|
637
|
+
.then(function () {
|
|
638
|
+
return resetHook._setState('idle');
|
|
639
|
+
})
|
|
640
|
+
.then(function () {
|
|
641
|
+
process.stdout.write(JSON.stringify({ ok: true, state: 'idle' }) + '\n');
|
|
642
|
+
process.exit(0);
|
|
643
|
+
})
|
|
644
|
+
.catch(function (error) {
|
|
645
|
+
console.error('Hook execution failed: ' + error.message);
|
|
646
|
+
process.exit(1);
|
|
647
|
+
});
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
readStdin(function (err, payload) {
|
|
609
652
|
if (err) {
|
|
610
653
|
console.error('Failed to read stdin: ' + err.message);
|
|
611
654
|
process.exit(1);
|
|
@@ -617,8 +660,13 @@ function main() {
|
|
|
617
660
|
hook
|
|
618
661
|
.onActivate(null)
|
|
619
662
|
.then(function () {
|
|
620
|
-
|
|
621
|
-
|
|
663
|
+
var context = normalizeHookContext(payload);
|
|
664
|
+
|
|
665
|
+
// Check for double-triggering prevention (same event + tool, 1s window).
|
|
666
|
+
// Only for state-changing --post-skill: --pre-tool is a pure read-only
|
|
667
|
+
// check and must NEVER be deduped (parallel Edit calls fire within 1s;
|
|
668
|
+
// skipping them would fail the waiting-block open).
|
|
669
|
+
if (mode === '--post-skill' && hook._shouldSkipForDoubleTrigger(context)) {
|
|
622
670
|
// Skip execution to prevent double-triggering
|
|
623
671
|
process.stdout.write(JSON.stringify({ allowed: true, skipped: true, reason: 'Double-trigger prevention' }) + '\n');
|
|
624
672
|
process.exit(0);
|
|
@@ -660,3 +708,4 @@ if (require.main === module) {
|
|
|
660
708
|
}
|
|
661
709
|
|
|
662
710
|
module.exports = SkillGateHook;
|
|
711
|
+
module.exports.normalizeHookContext = normalizeHookContext;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"type": "hook",
|
|
5
5
|
"description": "统一技能门控 Hook - 合并 check-state + post-skill + skill-gate 三合一,动态查询 gated skills",
|
|
6
|
-
"dependencies": [
|
|
6
|
+
"dependencies": [],
|
|
7
7
|
"provides": ["hook:skill-gate"],
|
|
8
8
|
"config": {
|
|
9
9
|
"gatedSkills": [],
|
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## ⚠️ 权限要求
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- 验证目录是否存在 (`test -d`)
|
|
11
|
-
- 调用 `team-cleanup` CLI 执行文件系统级删除(**CLI 直接走 fs.rmSync,不调用 TeamDelete**——该工具已从 harness 移除)
|
|
12
|
-
|
|
13
|
-
> **Step 7f 的文件系统删除由 `node bin/doukui.js team-cleanup <team> --force` 执行**——该 CLI 是 Node 进程,**绕过 harness Bash 权限系统**,无需在 settings.json 添加 `Bash(rm -rf ...)` 权限条目。只需 `Bash(node bin/doukui.js team-cleanup ...)` 一条。
|
|
9
|
+
Step 7 清理需要 Bash 权限执行 `test -d` 验证与 `node bin/doukui.js team-cleanup <team> --force`(该 CLI 是 Node 进程,内部走 fs.rmSync 文件系统级删除,不调用 TeamDelete——工具已移除;**无需**在 settings.json 添加 `Bash(rm -rf ...)` 条目,只需 `Bash(node bin/doukui.js team-cleanup ...)` 一条)。
|
|
14
10
|
|
|
15
11
|
> ⚠️ **implicit session team 模式下的清理范围**: 当前 session 的 implicit team 随 session 自动清理,**本流程主要针对历史残留的显式/UUID 团队目录**(如旧的 `cybershop-wp101`、UUID 命名团队)。若 `team_name` 是当前 session 的批次标签(非真实 harness 团队目录),目录可能不存在,Step 7a 条件 2 会返回 `NOT_FOUND` 并正常跳过。
|
|
16
12
|
|
|
@@ -69,17 +65,10 @@ Teamee 逻辑销毁必须完成 + 残留目录清理必须验证结果!
|
|
|
69
65
|
```
|
|
70
66
|
# 无协议帧;in-process Teamee 随 session 自然终止
|
|
71
67
|
teamee_map.clear()
|
|
72
|
-
#
|
|
73
|
-
# 输出: "映射表已清空(残留 Teamee 随 session 终止)"
|
|
68
|
+
# 输出: "映射表已清空(残留 Teamee 随 session 终止)" ← 直接文本输出,禁止用 SendMessage
|
|
74
69
|
```
|
|
75
70
|
|
|
76
|
-
>
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
### Step 7c: (已删除) 无需等待 shutdown 响应
|
|
81
|
-
|
|
82
|
-
逻辑销毁(Step 7b `teamee_map.clear()`)无协议帧,无需等待响应,直接进入残留目录清理(Step 7d)。
|
|
71
|
+
> 映射表不一致的孤儿成员会在后续 team-cleanup CLI 的目录级清理中被一并删除。
|
|
83
72
|
|
|
84
73
|
---
|
|
85
74
|
|
|
@@ -198,17 +187,7 @@ Owner: godot-script-expert-t2
|
|
|
198
187
|
|
|
199
188
|
## Cleanup Guarantee (清理保障)
|
|
200
189
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
│ ✅ 正常完成 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI │
|
|
206
|
-
│ ✅ 部分失败 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI │
|
|
207
|
-
│ ✅ 超时 → Step 6.5 超时逻辑销毁 → Step 7 强制 CLI │
|
|
208
|
-
│ ✅ 异常中断 → 捕获中断 → Step 7 强制逻辑销毁残留 + CLI │
|
|
209
|
-
│ │
|
|
210
|
-
│ ❌ 无任何情况可以跳过 Teamee 逻辑销毁! │
|
|
211
|
-
│ (当前 session implicit team 随 session 自动清理; │
|
|
212
|
-
│ team-cleanup CLI 仅清理历史残留显式/UUID 团队目录) │
|
|
213
|
-
└─────────────────────────────────────────────────────────────┘
|
|
214
|
-
```
|
|
190
|
+
- ✅ 正常完成 / 部分失败 → Step 6.5 即时逻辑销毁 → Step 7 历史残留 CLI
|
|
191
|
+
- ✅ 超时 → Step 6.5 超时逻辑销毁 → Step 7 强制 CLI
|
|
192
|
+
- ✅ 异常中断 → 捕获中断 → Step 7 强制逻辑销毁残留 + CLI
|
|
193
|
+
- ❌ **无任何情况可以跳过 Teamee 逻辑销毁**(当前 session implicit team 随 session 自动清理;team-cleanup CLI 仅清理历史残留显式/UUID 团队目录)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Dispatcher Monitoring Reference(监控循环运行时细则)
|
|
2
|
+
|
|
3
|
+
> 本文件是 skill-agent-dispatcher 的按需参考(渐进式加载约定)。规则本体与触发条件仍在 SKILL.md 主干(Step 6 / Step 6.5 监控循环 Phase C、拆分工作包执行支持、共享上下文机制);以下章节仅在遇到对应运行时场景时按 📖指针 Read,无需预载。
|
|
4
|
+
|
|
5
|
+
## 辅助函数(is_unblocked / 并发控制)
|
|
6
|
+
|
|
7
|
+
**辅助函数 — 判断任务是否已解除阻塞**:
|
|
8
|
+
```
|
|
9
|
+
def is_unblocked(task):
|
|
10
|
+
"""检查任务的所有 blockedBy 依赖是否都已满足"""
|
|
11
|
+
if not task.blockedBy:
|
|
12
|
+
return True
|
|
13
|
+
all_tasks = TaskList()
|
|
14
|
+
for blocker_id in task.blockedBy:
|
|
15
|
+
blocker = find_by_id(all_tasks, blocker_id)
|
|
16
|
+
if blocker.status != "completed":
|
|
17
|
+
return False
|
|
18
|
+
return True
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**辅助函数 — 并发控制**(Phase C 使用):
|
|
22
|
+
```
|
|
23
|
+
def get_max_concurrent(config, current_time):
|
|
24
|
+
"""根据当前时间匹配 schedule,返回对应并发上限"""
|
|
25
|
+
if not config or not config.get("schedules"):
|
|
26
|
+
return config.get("default_max", 6) if config else 6
|
|
27
|
+
|
|
28
|
+
current_hhmm = current_time.strftime("%H:%M")
|
|
29
|
+
for schedule in config["schedules"]:
|
|
30
|
+
start = schedule["time_range"]["start"]
|
|
31
|
+
end = schedule["time_range"]["end"]
|
|
32
|
+
if is_time_in_range(current_hhmm, start, end):
|
|
33
|
+
return schedule["max_concurrent"]
|
|
34
|
+
|
|
35
|
+
return config.get("default_max", 6)
|
|
36
|
+
|
|
37
|
+
def is_time_in_range(current, start, end):
|
|
38
|
+
"""判断当前时间是否在范围内,支持跨午夜"""
|
|
39
|
+
if start <= end:
|
|
40
|
+
return start <= current < end
|
|
41
|
+
else: # 跨午夜,如 22:00-06:00
|
|
42
|
+
return current >= start or current < end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
配置来源:`agent_dispatcher.concurrency`(plugin.json / harness-config.yaml,字段 `default_max` + `schedules[{name, time_range:{start,end}, max_concurrent}]`)。Phase C 每轮用 `get_max_concurrent(config, now())` 取当前时段上限,活跃 Teamee 数(`len(teamee_map)`)达上限即跳过创建、任务保持 pending。
|
|
46
|
+
|
|
47
|
+
## 拆分工作包执行支持
|
|
48
|
+
|
|
49
|
+
当工作包有子工作包时,agent-dispatcher 会自动识别并按依赖调度。
|
|
50
|
+
|
|
51
|
+
### 执行流程
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
1. 读取父工作包文档 (docs/wp/WP-XXX.md)
|
|
55
|
+
2. 检测拆分模式 (simple/standard/fine-grained)
|
|
56
|
+
3. 解析子工作包列表 + 依赖关系
|
|
57
|
+
4. 创建 Task List 任务 + 设置 blockedBy
|
|
58
|
+
5. 角色匹配 → 分配角色
|
|
59
|
+
6. 按依赖顺序调度执行
|
|
60
|
+
7. 验证关卡: verify 失败 → 停止后续; verify 通过 → 继续
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 拆分模式处理
|
|
64
|
+
|
|
65
|
+
| 模式 | 处理方式 |
|
|
66
|
+
|------|----------|
|
|
67
|
+
| **simple** | 不拆分,直接作为单个任务调度 |
|
|
68
|
+
| **standard** | 4 个子任务: impl → test → verify → review(依赖链) |
|
|
69
|
+
| **fine-grained** | 按模块拆分多个 impl,每个独立 test,最后统一 verify + review |
|
|
70
|
+
|
|
71
|
+
## 共享上下文机制
|
|
72
|
+
|
|
73
|
+
### 自动共享 (无需干预)
|
|
74
|
+
|
|
75
|
+
| 资源 | 共享方式 |
|
|
76
|
+
|------|----------|
|
|
77
|
+
| `CLAUDE.md` | 所有 Teamee 自动加载 |
|
|
78
|
+
| Skills | 继承 Lead 的 skills |
|
|
79
|
+
| MCP Servers | 共享相同的 MCP 配置 |
|
|
80
|
+
| 项目代码 | 共享同一工作目录 |
|
|
81
|
+
|
|
82
|
+
### 主动共享 (通过 SendMessage)
|
|
83
|
+
|
|
84
|
+
> Teamee 一经 spawn **自动加入 implicit session team**——SendMessage 与共享 Task List 的协作能力由 implicit session team 提供。
|
|
85
|
+
|
|
86
|
+
| 消息类型 | 格式 | 用途 |
|
|
87
|
+
|----------|------|------|
|
|
88
|
+
| `shutdown_request` / `shutdown_response` | (deprecated) | 不再使用;harness 拦截含 protocol frame 的 SendMessage message。Teamee 状态同步改为 TaskUpdate(completed) → Lead 检测 → markTeameeDestroyed |
|
|
89
|
+
| 纯文本状态 | string + summary | Teamee 间/向 Lead 的进度沟通(唯一允许的 SendMessage 用途) |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "skill",
|
|
5
5
|
"description": "Use when user says \"批量执行\", \"并行执行\", \"调度子代理\", or needs to execute multiple work packages using Agent subagents. Analyzes dependencies and dispatches tasks in parallel or sequential order.",
|
|
6
6
|
"triggers": ["批量执行", "并行执行", "调度子代理", "agent-dispatcher", "batch execute", "parallel execute", "dispatch agents"],
|
|
7
|
-
"dependencies": ["provider:role-registry"
|
|
7
|
+
"dependencies": ["provider:role-registry"],
|
|
8
8
|
"provides": ["skill:agent-dispatcher"],
|
|
9
9
|
"metadata": {
|
|
10
10
|
"gatedByCode": true
|