doukui 0.8.0 → 0.9.1
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 +8 -8
- package/bin/commands/help.js +2 -0
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +2 -0
- package/package.json +1 -1
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +154 -19
- 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 +5 -177
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
- package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
- package/plugins/core/skill-agentic-loop/plugin.json +1 -1
- package/plugins/core/skill-agentic-loop/skill.md +123 -324
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-batch-task-creator/skill.md +22 -24
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +33 -38
- 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-split-work-package/skill.md +20 -18
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +25 -165
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -36
- package/plugins/runtime/claude-md-injector.js +1 -0
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +21 -3
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/plugins/runtime/settings-merger.js +5 -0
- package/plugins/contracts/capabilities.js +0 -268
- 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/event-bus.js +0 -207
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- 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/text-tokenize.js +0 -24
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HookDispatcher - Dual-mode hook execution dispatcher for AI Agent Harness
|
|
3
|
-
*
|
|
4
|
-
* Two execution modes:
|
|
5
|
-
* - External: Command-based execution via settings.json (default, backward compatible)
|
|
6
|
-
* - Internal: Programmatic execution by calling HookPlugin.handle() directly
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* - Route hook events to appropriate hooks based on trigger configuration
|
|
10
|
-
* - Support PreToolUse, PostToolUse, SessionStart event types
|
|
11
|
-
* - Priority-based hook execution (lower priority = earlier execution)
|
|
12
|
-
* - Graceful handling of unregistered events
|
|
13
|
-
* - Integration with PluginLoader for internal mode
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
* const dispatcher = new HookDispatcher({ pluginLoader, logger });
|
|
17
|
-
* await dispatcher.dispatch({ event: 'PreToolUse', tool: 'Edit', ... });
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
'use strict';
|
|
21
|
-
|
|
22
|
-
var { PluginType, PluginState } = require('../contracts/plugin-interface');
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Execution mode constants.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
var ExecutionMode = Object.freeze({
|
|
29
|
-
EXTERNAL: 'external', // Command-based via settings.json (default)
|
|
30
|
-
INTERNAL: 'internal', // Programmatic via HookPlugin.handle()
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Default configuration.
|
|
35
|
-
*/
|
|
36
|
-
var DEFAULT_CONFIG = {
|
|
37
|
-
mode: ExecutionMode.EXTERNAL,
|
|
38
|
-
priorityThreshold: 1000,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* HookDispatcher class.
|
|
43
|
-
* @public
|
|
44
|
-
*/
|
|
45
|
-
class HookDispatcher {
|
|
46
|
-
/**
|
|
47
|
-
* @public
|
|
48
|
-
* @param {object} options
|
|
49
|
-
* @param {object} options.pluginLoader - PluginLoader instance (required for internal mode)
|
|
50
|
-
* @param {object} options.logger - Logger instance (optional)
|
|
51
|
-
* @param {string} [options.mode] - default execution mode
|
|
52
|
-
*/
|
|
53
|
-
constructor(options) {
|
|
54
|
-
options = options || {};
|
|
55
|
-
this._pluginLoader = options.pluginLoader || null;
|
|
56
|
-
this._logger = options.logger || null;
|
|
57
|
-
this._mode = options.mode || DEFAULT_CONFIG.mode;
|
|
58
|
-
this._priorityThreshold = options.priorityThreshold || DEFAULT_CONFIG.priorityThreshold;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Dispatch a hook event to appropriate hooks.
|
|
63
|
-
*
|
|
64
|
-
* @public
|
|
65
|
-
* @param {object} context
|
|
66
|
-
* @param {string} context.event - Event type: 'PreToolUse', 'PostToolUse', 'SessionStart'
|
|
67
|
-
* @param {string} [context.tool] - Tool name (for PreToolUse/PostToolUse)
|
|
68
|
-
* @param {string} [context.skill] - Skill name (for PostToolUse)
|
|
69
|
-
* @param {string} [context.mode] - Override execution mode for this call
|
|
70
|
-
* @returns {Promise<{ allowed: boolean, results?: object[], reason?: string }>}
|
|
71
|
-
*/
|
|
72
|
-
async dispatch(context) {
|
|
73
|
-
if (!context || !context.event) {
|
|
74
|
-
this._log('warn', 'dispatch() called with invalid context');
|
|
75
|
-
return { allowed: true, results: [] };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
var mode = context.mode || this._mode;
|
|
79
|
-
this._log('debug', 'Dispatching event "' + context.event + '" in ' + mode + ' mode');
|
|
80
|
-
|
|
81
|
-
if (mode === ExecutionMode.INTERNAL) {
|
|
82
|
-
return await this._dispatchInternal(context);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// External mode: no-op (hooks are executed via settings.json commands)
|
|
86
|
-
return { allowed: true, results: [], mode: 'external' };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Internal mode dispatch: call loaded HookPlugin.handle() directly.
|
|
91
|
-
*
|
|
92
|
-
* @param {object} context
|
|
93
|
-
* @returns {Promise<{ allowed: boolean, results: object[], reason?: string }>}
|
|
94
|
-
* @private
|
|
95
|
-
*/
|
|
96
|
-
async _dispatchInternal(context) {
|
|
97
|
-
if (!this._pluginLoader) {
|
|
98
|
-
this._log('warn', 'Internal mode requested but no pluginLoader provided');
|
|
99
|
-
return { allowed: true, results: [], mode: 'internal' };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
var matchingHooks = this._findMatchingHooks(context);
|
|
103
|
-
if (matchingHooks.length === 0) {
|
|
104
|
-
this._log('debug', 'No matching hooks found for event "' + context.event + '"');
|
|
105
|
-
return { allowed: true, results: [], mode: 'internal' };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Sort by priority (lower = earlier execution)
|
|
109
|
-
matchingHooks.sort(function (a, b) {
|
|
110
|
-
var pa = (a.plugin && a.plugin.priority) || 100;
|
|
111
|
-
var pb = (b.plugin && b.plugin.priority) || 100;
|
|
112
|
-
return pa - pb;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
this._log('debug', 'Found ' + matchingHooks.length + ' matching hook(s)');
|
|
116
|
-
|
|
117
|
-
var results = [];
|
|
118
|
-
var overallAllowed = true;
|
|
119
|
-
var blockReason = null;
|
|
120
|
-
|
|
121
|
-
for (var i = 0; i < matchingHooks.length; i++) {
|
|
122
|
-
var item = matchingHooks[i];
|
|
123
|
-
var plugin = item.plugin;
|
|
124
|
-
|
|
125
|
-
// Skip inactive plugins
|
|
126
|
-
if (plugin.state !== PluginState.ACTIVATED) {
|
|
127
|
-
this._log('debug', 'Hook "' + plugin.name + '" is not activated, skipping');
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
this._log('debug', 'Executing hook "' + plugin.name + '" (priority: ' + plugin.priority + ')');
|
|
133
|
-
var result = await plugin.handle(context);
|
|
134
|
-
results.push({
|
|
135
|
-
hook: plugin.name,
|
|
136
|
-
result: result,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// If any hook disallows, set overall allowed to false
|
|
140
|
-
if (result && result.allowed === false) {
|
|
141
|
-
overallAllowed = false;
|
|
142
|
-
blockReason = result.reason || ('Blocked by hook: ' + plugin.name);
|
|
143
|
-
this._log('info', 'Hook "' + plugin.name + '" disallowed action: ' + blockReason);
|
|
144
|
-
// Continue executing remaining hooks for side effects
|
|
145
|
-
}
|
|
146
|
-
} catch (err) {
|
|
147
|
-
this._log('error', 'Hook "' + plugin.name + '" threw error: ' + err.message);
|
|
148
|
-
results.push({
|
|
149
|
-
hook: plugin.name,
|
|
150
|
-
error: err.message,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
var response = {
|
|
156
|
-
allowed: overallAllowed,
|
|
157
|
-
results: results,
|
|
158
|
-
mode: 'internal',
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
if (blockReason) {
|
|
162
|
-
response.reason = blockReason;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return response;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Find all loaded hooks that match the event context.
|
|
170
|
-
*
|
|
171
|
-
* @param {object} context
|
|
172
|
-
* @returns {Array<{ plugin: HookPlugin, trigger: object }>}
|
|
173
|
-
* @private
|
|
174
|
-
*/
|
|
175
|
-
_findMatchingHooks(context) {
|
|
176
|
-
var matches = [];
|
|
177
|
-
var loadedNames = this._pluginLoader.getLoadedNames();
|
|
178
|
-
|
|
179
|
-
for (var i = 0; i < loadedNames.length; i++) {
|
|
180
|
-
var plugin = this._pluginLoader.getPlugin(loadedNames[i]);
|
|
181
|
-
|
|
182
|
-
if (!plugin || plugin.type !== PluginType.HOOK) {
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
var trigger = plugin.trigger || {};
|
|
187
|
-
|
|
188
|
-
// Check event type match
|
|
189
|
-
if (trigger.event !== context.event) {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Check tool filter (for PreToolUse/PostToolUse)
|
|
194
|
-
if (trigger.tools && trigger.tools.length > 0) {
|
|
195
|
-
var tool = context.tool || '';
|
|
196
|
-
var toolMatched = false;
|
|
197
|
-
for (var j = 0; j < trigger.tools.length; j++) {
|
|
198
|
-
if (trigger.tools[j] === tool) {
|
|
199
|
-
toolMatched = true;
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (!toolMatched) continue;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Check skill filter (for PostToolUse)
|
|
207
|
-
if (trigger.skills && trigger.skills.length > 0) {
|
|
208
|
-
var skill = context.skill || '';
|
|
209
|
-
var skillMatched = false;
|
|
210
|
-
for (var k = 0; k < trigger.skills.length; k++) {
|
|
211
|
-
if (trigger.skills[k] === skill) {
|
|
212
|
-
skillMatched = true;
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (!skillMatched) continue;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
matches.push({
|
|
220
|
-
plugin: plugin,
|
|
221
|
-
trigger: trigger,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return matches;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Set the default execution mode.
|
|
230
|
-
* @public
|
|
231
|
-
* @param {string} mode - 'external' or 'internal'
|
|
232
|
-
*/
|
|
233
|
-
setMode(mode) {
|
|
234
|
-
if (mode !== ExecutionMode.EXTERNAL && mode !== ExecutionMode.INTERNAL) {
|
|
235
|
-
throw new Error('Invalid mode: ' + mode + '. Use "external" or "internal"');
|
|
236
|
-
}
|
|
237
|
-
this._mode = mode;
|
|
238
|
-
this._log('info', 'Execution mode set to "' + mode + '"');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Get the current default execution mode.
|
|
243
|
-
* @public
|
|
244
|
-
* @returns {string}
|
|
245
|
-
*/
|
|
246
|
-
getMode() {
|
|
247
|
-
return this._mode;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Check if internal mode is available (requires pluginLoader).
|
|
252
|
-
* @public
|
|
253
|
-
* @returns {boolean}
|
|
254
|
-
*/
|
|
255
|
-
canUseInternalMode() {
|
|
256
|
-
return this._pluginLoader !== null;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Get statistics about loaded hooks.
|
|
261
|
-
* @public
|
|
262
|
-
* @returns {{ total: number, byEvent: object, byPriority: object[] }}
|
|
263
|
-
*/
|
|
264
|
-
getHookStats() {
|
|
265
|
-
if (!this._pluginLoader) {
|
|
266
|
-
return { total: 0, byEvent: {}, byPriority: [] };
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
var stats = {
|
|
270
|
-
total: 0,
|
|
271
|
-
byEvent: {},
|
|
272
|
-
byPriority: [],
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
var loadedNames = this._pluginLoader.getLoadedNames();
|
|
276
|
-
for (var i = 0; i < loadedNames.length; i++) {
|
|
277
|
-
var plugin = this._pluginLoader.getPlugin(loadedNames[i]);
|
|
278
|
-
if (!plugin || plugin.type !== PluginType.HOOK) continue;
|
|
279
|
-
|
|
280
|
-
stats.total++;
|
|
281
|
-
|
|
282
|
-
var event = (plugin.trigger && plugin.trigger.event) || 'unknown';
|
|
283
|
-
stats.byEvent[event] = (stats.byEvent[event] || 0) + 1;
|
|
284
|
-
|
|
285
|
-
stats.byPriority.push({
|
|
286
|
-
name: plugin.name,
|
|
287
|
-
event: event,
|
|
288
|
-
priority: plugin.priority || 100,
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
stats.byPriority.sort(function (a, b) {
|
|
293
|
-
return a.priority - b.priority;
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
return stats;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Internal logging helper.
|
|
301
|
-
* @param {string} level
|
|
302
|
-
* @param {string} message
|
|
303
|
-
* @private
|
|
304
|
-
*/
|
|
305
|
-
_log(level, message) {
|
|
306
|
-
if (this._logger && typeof this._logger[level] === 'function') {
|
|
307
|
-
this._logger[level]('hook-dispatcher', message);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
module.exports = {
|
|
313
|
-
HookDispatcher,
|
|
314
|
-
ExecutionMode,
|
|
315
|
-
};
|