doukui 0.8.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 +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 +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 +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-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 +22 -22
- 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 -36
- 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/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,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,24 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
// 共享分词(WP-S4 从 provider-memory-store._tokenize 提取)
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
// 中文按字符 bigram(无词典依赖),拉丁/数字按词。消费方:
|
|
7
|
-
// - provider-memory-store.recall(记忆召回打分)
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 分词:拉丁词(小写)+ 中文字符 bigram。
|
|
12
|
-
* @param {string} text
|
|
13
|
-
* @returns {string[]}
|
|
14
|
-
*/
|
|
15
|
-
function tokenize(text) {
|
|
16
|
-
var tokens = [];
|
|
17
|
-
var latin = String(text || '').toLowerCase().match(/[a-z0-9_]+/g) || [];
|
|
18
|
-
for (var i = 0; i < latin.length; i++) tokens.push(latin[i]);
|
|
19
|
-
var cjk = String(text || '').match(/[\u4e00-\u9fff]/g) || [];
|
|
20
|
-
for (var j = 0; j < cjk.length - 1; j++) tokens.push(cjk[j] + cjk[j + 1]);
|
|
21
|
-
return tokens;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = { tokenize: tokenize };
|
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ValidatorPipeline - Validator execution pipeline for AI Agent Harness
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Execute registered validators at workflow checkpoints
|
|
6
|
-
* - Support blocking mode (fail fast) and non-blocking mode (warnings only)
|
|
7
|
-
* - Auto-run validator-doc-sync after build
|
|
8
|
-
* - Auto-run validator-work-package when WP changes
|
|
9
|
-
* - Event-driven integration with EventBus
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* var pipeline = new ValidatorPipeline({
|
|
13
|
-
* pluginLoader: pluginLoader,
|
|
14
|
-
* eventBus: eventBus,
|
|
15
|
-
* logger: logger,
|
|
16
|
-
* });
|
|
17
|
-
* await pipeline.runValidator('validator-doc-sync', { blocking: false });
|
|
18
|
-
* var result = await pipeline.runAllValidators({ phase: 'build' });
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
'use strict';
|
|
22
|
-
|
|
23
|
-
var path = require('path');
|
|
24
|
-
|
|
25
|
-
// ---------------------------------------------------------------------------
|
|
26
|
-
// Constants
|
|
27
|
-
// ---------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Validator execution modes.
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
var ExecutionMode = {
|
|
34
|
-
BLOCKING: 'blocking', // Fail on validation error, stop workflow
|
|
35
|
-
NON_BLOCKING: 'non-blocking', // Continue on error, log warnings
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Workflow phases where validators auto-trigger.
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
var WorkflowPhase = {
|
|
43
|
-
BUILD: 'build', // After `doukui build` completes
|
|
44
|
-
WP_CREATE: 'wp-create', // After WP document creation
|
|
45
|
-
WP_MODIFY: 'wp-modify', // After WP document modification
|
|
46
|
-
MANUAL: 'manual', // Explicit manual invocation
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// ValidatorPipeline class
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* ValidatorPipeline constructor.
|
|
55
|
-
* @public
|
|
56
|
-
* @param {object} options
|
|
57
|
-
* @param {object} options.pluginLoader - PluginLoader instance
|
|
58
|
-
* @param {object} options.eventBus - EventBus instance
|
|
59
|
-
* @param {object} options.logger - Logger instance
|
|
60
|
-
* @param {string} [options.projectRoot] - Project root directory (default: cwd)
|
|
61
|
-
*/
|
|
62
|
-
function ValidatorPipeline(options) {
|
|
63
|
-
options = options || {};
|
|
64
|
-
|
|
65
|
-
if (!options.pluginLoader) {
|
|
66
|
-
throw new Error('ValidatorPipeline: pluginLoader is required');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this._pluginLoader = options.pluginLoader;
|
|
70
|
-
this._eventBus = options.eventBus || null;
|
|
71
|
-
this._logger = options.logger || null;
|
|
72
|
-
this._projectRoot = options.projectRoot || process.cwd();
|
|
73
|
-
|
|
74
|
-
/** @type {Map<string, object>} validator execution results cache */
|
|
75
|
-
this._resultsCache = new Map();
|
|
76
|
-
|
|
77
|
-
this._setupEventListeners();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ---------------------------------------------------------------------------
|
|
81
|
-
// Public API
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Run a single validator by name.
|
|
86
|
-
*
|
|
87
|
-
* @public
|
|
88
|
-
* @param {string} validatorName - registered validator plugin name
|
|
89
|
-
* @param {object} [options]
|
|
90
|
-
* @param {string} [options.mode='blocking'] - ExecutionMode: 'blocking' or 'non-blocking'
|
|
91
|
-
* @param {object} [options.context] - Additional context to pass to validator
|
|
92
|
-
* @returns {Promise<{ passed: boolean, errors: object[], warnings: object[], mode: string }>}
|
|
93
|
-
*/
|
|
94
|
-
ValidatorPipeline.prototype.runValidator = async function runValidator(validatorName, options) {
|
|
95
|
-
options = options || {};
|
|
96
|
-
var mode = options.mode || ExecutionMode.BLOCKING;
|
|
97
|
-
var context = options.context || {};
|
|
98
|
-
|
|
99
|
-
this._log('info', 'Running validator: ' + validatorName + ' (mode: ' + mode + ')');
|
|
100
|
-
|
|
101
|
-
// Get the validator plugin instance
|
|
102
|
-
var validator = this._pluginLoader.getPlugin(validatorName);
|
|
103
|
-
if (!validator) {
|
|
104
|
-
var error = 'Validator plugin "' + validatorName + '" is not loaded';
|
|
105
|
-
this._log('error', error);
|
|
106
|
-
if (mode === ExecutionMode.BLOCKING) {
|
|
107
|
-
throw new Error(error);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
passed: false,
|
|
111
|
-
errors: [{ message: error }],
|
|
112
|
-
warnings: [],
|
|
113
|
-
mode: mode,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Verify it's actually a ValidatorPlugin
|
|
118
|
-
if (validator.type !== 'validator') {
|
|
119
|
-
error = 'Plugin "' + validatorName + '" is not a validator (type: ' + validator.type + ')';
|
|
120
|
-
this._log('error', error);
|
|
121
|
-
if (mode === ExecutionMode.BLOCKING) {
|
|
122
|
-
throw new Error(error);
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
passed: false,
|
|
126
|
-
errors: [{ message: error }],
|
|
127
|
-
warnings: [],
|
|
128
|
-
mode: mode,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Execute the validator
|
|
133
|
-
var result;
|
|
134
|
-
try {
|
|
135
|
-
result = await validator.validate(context);
|
|
136
|
-
} catch (err) {
|
|
137
|
-
this._log('error', 'Validator "' + validatorName + '" threw exception: ' + err.message);
|
|
138
|
-
result = {
|
|
139
|
-
valid: false,
|
|
140
|
-
errors: [{ message: 'Exception during validation: ' + err.message }],
|
|
141
|
-
warnings: [],
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Normalize result format (validators may return { valid, errors, warnings } or { passed, errors, warnings })
|
|
146
|
-
var passed = result.valid !== undefined ? result.valid : (result.passed || false);
|
|
147
|
-
var errors = result.errors || [];
|
|
148
|
-
var warnings = result.warnings || [];
|
|
149
|
-
|
|
150
|
-
// Build standardized result
|
|
151
|
-
var stdResult = {
|
|
152
|
-
passed: passed,
|
|
153
|
-
errors: errors,
|
|
154
|
-
warnings: warnings,
|
|
155
|
-
mode: mode,
|
|
156
|
-
validator: validatorName,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Emit event
|
|
160
|
-
if (this._eventBus) {
|
|
161
|
-
this._eventBus.emit('validator:executed', {
|
|
162
|
-
validator: validatorName,
|
|
163
|
-
passed: passed,
|
|
164
|
-
mode: mode,
|
|
165
|
-
errorsCount: errors.length,
|
|
166
|
-
warningsCount: warnings.length,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Log results
|
|
171
|
-
if (passed) {
|
|
172
|
-
this._log('info', 'Validator "' + validatorName + '" PASSED' + (warnings.length > 0 ? ' with ' + warnings.length + ' warnings' : ''));
|
|
173
|
-
} else {
|
|
174
|
-
this._log('error', 'Validator "' + validatorName + '" FAILED: ' + errors.length + ' errors');
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Cache result
|
|
178
|
-
this._resultsCache.set(validatorName, stdResult);
|
|
179
|
-
|
|
180
|
-
// Handle blocking mode
|
|
181
|
-
if (mode === ExecutionMode.BLOCKING && !passed) {
|
|
182
|
-
var errorMessages = errors.map(function (e) { return e.message || String(e); });
|
|
183
|
-
throw new Error('Validator "' + validatorName + '" failed in blocking mode:\n - ' + errorMessages.join('\n - '));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return stdResult;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Run all registered validators for a specific workflow phase.
|
|
191
|
-
*
|
|
192
|
-
* @public
|
|
193
|
-
* @param {object} [options]
|
|
194
|
-
* @param {string} [options.phase='manual'] - WorkflowPhase identifier
|
|
195
|
-
* @param {string} [options.mode='blocking'] - Default execution mode (can be overridden per-validator)
|
|
196
|
-
* @param {boolean} [options.stopOnFirstError=false] - Stop execution on first blocking failure
|
|
197
|
-
* @returns {Promise<{ results: object[], overallPassed: boolean, totalErrors: number, totalWarnings: number }>}
|
|
198
|
-
*/
|
|
199
|
-
ValidatorPipeline.prototype.runAllValidators = async function runAllValidators(options) {
|
|
200
|
-
options = options || {};
|
|
201
|
-
var phase = options.phase || WorkflowPhase.MANUAL;
|
|
202
|
-
var defaultMode = options.mode || ExecutionMode.BLOCKING;
|
|
203
|
-
// B5: default false per JSDoc above (was previously true due to `!== false`
|
|
204
|
-
// idiom evaluating undefined → true). Callers that want short-circuit
|
|
205
|
-
// behavior must pass stopOnFirstError: true explicitly.
|
|
206
|
-
var stopOnFirstError = options.stopOnFirstError === true;
|
|
207
|
-
|
|
208
|
-
this._log('info', 'Running all validators for phase: ' + phase);
|
|
209
|
-
|
|
210
|
-
var loadedPlugins = this._pluginLoader.getLoadedNames();
|
|
211
|
-
var validatorNames = [];
|
|
212
|
-
|
|
213
|
-
// Find all validator plugins
|
|
214
|
-
for (var i = 0; i < loadedPlugins.length; i++) {
|
|
215
|
-
var plugin = this._pluginLoader.getPlugin(loadedPlugins[i]);
|
|
216
|
-
if (plugin && plugin.type === 'validator') {
|
|
217
|
-
validatorNames.push(loadedPlugins[i]);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (validatorNames.length === 0) {
|
|
222
|
-
this._log('info', 'No validators registered, skipping');
|
|
223
|
-
return {
|
|
224
|
-
results: [],
|
|
225
|
-
overallPassed: true,
|
|
226
|
-
totalErrors: 0,
|
|
227
|
-
totalWarnings: 0,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
var results = [];
|
|
232
|
-
var totalErrors = 0;
|
|
233
|
-
var totalWarnings = 0;
|
|
234
|
-
var overallPassed = true;
|
|
235
|
-
|
|
236
|
-
// Determine which validators to run based on phase
|
|
237
|
-
var validatorsToRun = this._filterValidatorsForPhase(validatorNames, phase);
|
|
238
|
-
|
|
239
|
-
for (var j = 0; j < validatorsToRun.length; j++) {
|
|
240
|
-
var validatorName = validatorsToRun[j];
|
|
241
|
-
var validator = this._pluginLoader.getPlugin(validatorName);
|
|
242
|
-
|
|
243
|
-
// Determine execution mode from validator config or default
|
|
244
|
-
var mode = defaultMode;
|
|
245
|
-
if (validator && validator.blocking === false) {
|
|
246
|
-
mode = ExecutionMode.NON_BLOCKING;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
try {
|
|
250
|
-
var result = await this.runValidator(validatorName, { mode: mode, phase: phase });
|
|
251
|
-
results.push(result);
|
|
252
|
-
|
|
253
|
-
if (!result.passed) {
|
|
254
|
-
overallPassed = false;
|
|
255
|
-
totalErrors += result.errors.length;
|
|
256
|
-
}
|
|
257
|
-
totalWarnings += result.warnings.length;
|
|
258
|
-
|
|
259
|
-
// Stop on first blocking error if requested
|
|
260
|
-
if (stopOnFirstError && mode === ExecutionMode.BLOCKING && !result.passed) {
|
|
261
|
-
this._log('warn', 'Stopping validator execution due to blocking failure');
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
} catch (err) {
|
|
265
|
-
// runValidator throws in blocking mode on failure
|
|
266
|
-
overallPassed = false;
|
|
267
|
-
totalErrors += 1;
|
|
268
|
-
results.push({
|
|
269
|
-
validator: validatorName,
|
|
270
|
-
passed: false,
|
|
271
|
-
errors: [{ message: err.message }],
|
|
272
|
-
warnings: [],
|
|
273
|
-
mode: mode,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
if (stopOnFirstError && mode === ExecutionMode.BLOCKING) {
|
|
277
|
-
throw err;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
var summary = {
|
|
283
|
-
results: results,
|
|
284
|
-
overallPassed: overallPassed,
|
|
285
|
-
totalErrors: totalErrors,
|
|
286
|
-
totalWarnings: totalWarnings,
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// Emit completion event
|
|
290
|
-
if (this._eventBus) {
|
|
291
|
-
this._eventBus.emit('validator:phase-complete', {
|
|
292
|
-
phase: phase,
|
|
293
|
-
overallPassed: overallPassed,
|
|
294
|
-
totalErrors: totalErrors,
|
|
295
|
-
totalWarnings: totalWarnings,
|
|
296
|
-
validatorsExecuted: validatorsToRun.length,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
this._log('info', 'Validator phase complete: ' + (overallPassed ? 'PASSED' : 'FAILED') + ' (' + totalErrors + ' errors, ' + totalWarnings + ' warnings)');
|
|
301
|
-
|
|
302
|
-
return summary;
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Run validators specifically for post-build phase.
|
|
307
|
-
* This is a convenience method for the build workflow.
|
|
308
|
-
*
|
|
309
|
-
* @public
|
|
310
|
-
*
|
|
311
|
-
* @param {object} [options]
|
|
312
|
-
* @returns {Promise<object>}
|
|
313
|
-
*/
|
|
314
|
-
ValidatorPipeline.prototype.runPostBuildValidators = async function runPostBuildValidators(options) {
|
|
315
|
-
options = options || {};
|
|
316
|
-
options.phase = WorkflowPhase.BUILD;
|
|
317
|
-
options.mode = options.mode || ExecutionMode.NON_BLOCKING; // Build should not fail on validation
|
|
318
|
-
return await this.runAllValidators(options);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Run validators for WP-related operations.
|
|
323
|
-
* This is a convenience method for WP creation/modification workflow.
|
|
324
|
-
*
|
|
325
|
-
* @public
|
|
326
|
-
*
|
|
327
|
-
* @param {string} wpId - Work package ID (e.g., 'WP-001')
|
|
328
|
-
* @param {string} operation - 'create' or 'modify'
|
|
329
|
-
* @param {object} [options]
|
|
330
|
-
* @returns {Promise<object>}
|
|
331
|
-
*/
|
|
332
|
-
ValidatorPipeline.prototype.runWPValidators = async function runWPValidators(wpId, operation, options) {
|
|
333
|
-
options = options || {};
|
|
334
|
-
var phase = operation === 'create' ? WorkflowPhase.WP_CREATE : WorkflowPhase.WP_MODIFY;
|
|
335
|
-
|
|
336
|
-
this._log('info', 'Running WP validators for ' + wpId + ' (operation: ' + operation + ')');
|
|
337
|
-
|
|
338
|
-
// Build context with WP-specific info
|
|
339
|
-
var context = options.context || {};
|
|
340
|
-
context.wpId = wpId;
|
|
341
|
-
context.operation = operation;
|
|
342
|
-
context.wpPath = context.wpPath || path.join(this._projectRoot, 'docs', 'wp', wpId + '.md');
|
|
343
|
-
|
|
344
|
-
options.phase = phase;
|
|
345
|
-
options.context = context;
|
|
346
|
-
|
|
347
|
-
return await this.runAllValidators(options);
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Get cached validator result.
|
|
352
|
-
* @public
|
|
353
|
-
* @param {string} validatorName
|
|
354
|
-
* @returns {object|undefined}
|
|
355
|
-
*/
|
|
356
|
-
ValidatorPipeline.prototype.getCachedResult = function getCachedResult(validatorName) {
|
|
357
|
-
return this._resultsCache.get(validatorName);
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Clear all cached validator results.
|
|
362
|
-
* @public
|
|
363
|
-
*/
|
|
364
|
-
ValidatorPipeline.prototype.clearCache = function clearCache() {
|
|
365
|
-
this._resultsCache.clear();
|
|
366
|
-
this._log('info', 'Validator result cache cleared');
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
// Internal helpers
|
|
371
|
-
// ---------------------------------------------------------------------------
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Set up event listeners for automatic validator triggering.
|
|
375
|
-
* @internal
|
|
376
|
-
*/
|
|
377
|
-
ValidatorPipeline.prototype._setupEventListeners = function _setupEventListeners() {
|
|
378
|
-
if (!this._eventBus) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
var self = this;
|
|
383
|
-
|
|
384
|
-
// Listen for build completion events
|
|
385
|
-
this._eventBus.on('build:complete', function () {
|
|
386
|
-
self._log('info', 'Build complete detected, running post-build validators');
|
|
387
|
-
self.runPostBuildValidators().catch(function (err) {
|
|
388
|
-
self._log('error', 'Post-build validation failed: ' + err.message);
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
// Listen for WP document events
|
|
393
|
-
this._eventBus.on('wp:created', function (data) {
|
|
394
|
-
var wpId = data && data.wpId;
|
|
395
|
-
if (wpId) {
|
|
396
|
-
self._log('info', 'WP created detected: ' + wpId);
|
|
397
|
-
self.runWPValidators(wpId, 'create').catch(function (err) {
|
|
398
|
-
self._log('error', 'WP validation failed: ' + err.message);
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
this._eventBus.on('wp:modified', function (data) {
|
|
404
|
-
var wpId = data && data.wpId;
|
|
405
|
-
if (wpId) {
|
|
406
|
-
self._log('info', 'WP modified detected: ' + wpId);
|
|
407
|
-
self.runWPValidators(wpId, 'modify').catch(function (err) {
|
|
408
|
-
self._log('error', 'WP validation failed: ' + err.message);
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Filter validators based on workflow phase.
|
|
416
|
-
* Each validator can declare which phases it applies to via metadata.targets or similar.
|
|
417
|
-
*
|
|
418
|
-
* @internal
|
|
419
|
-
* @param {string[]} validatorNames
|
|
420
|
-
* @param {string} phase
|
|
421
|
-
* @returns {string[]}
|
|
422
|
-
*/
|
|
423
|
-
ValidatorPipeline.prototype._filterValidatorsForPhase = function _filterValidatorsForPhase(validatorNames, phase) {
|
|
424
|
-
var filtered = [];
|
|
425
|
-
|
|
426
|
-
for (var i = 0; i < validatorNames.length; i++) {
|
|
427
|
-
var validatorName = validatorNames[i];
|
|
428
|
-
var validator = this._pluginLoader.getPlugin(validatorName);
|
|
429
|
-
|
|
430
|
-
if (!validator) {
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Check if validator has explicit phase targeting
|
|
435
|
-
// First check metadata.targets (from plugin.json), then fall back to instance.targets
|
|
436
|
-
var targets = validator.metadata && validator.metadata.targets;
|
|
437
|
-
if (!targets || (Array.isArray(targets) && targets.length === 0)) {
|
|
438
|
-
targets = validator.targets;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (targets && Array.isArray(targets) && targets.length > 0) {
|
|
442
|
-
// Check if current phase is in targets
|
|
443
|
-
var targetsLower = targets.map(function (t) { return String(t).toLowerCase(); });
|
|
444
|
-
var phaseLower = phase.toLowerCase();
|
|
445
|
-
|
|
446
|
-
if (targetsLower.indexOf(phaseLower) !== -1 || targetsLower.indexOf('all') !== -1) {
|
|
447
|
-
filtered.push(validatorName);
|
|
448
|
-
}
|
|
449
|
-
} else {
|
|
450
|
-
// No explicit targets - apply to all phases
|
|
451
|
-
filtered.push(validatorName);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return filtered;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Internal logging helper.
|
|
460
|
-
*/
|
|
461
|
-
ValidatorPipeline.prototype._log = function _log(level, message) {
|
|
462
|
-
if (this._logger && typeof this._logger[level] === 'function') {
|
|
463
|
-
this._logger[level]('validator-pipeline', message);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
// ---------------------------------------------------------------------------
|
|
468
|
-
// Module exports
|
|
469
|
-
// ---------------------------------------------------------------------------
|
|
470
|
-
|
|
471
|
-
module.exports = {
|
|
472
|
-
ValidatorPipeline: ValidatorPipeline,
|
|
473
|
-
ExecutionMode: ExecutionMode,
|
|
474
|
-
WorkflowPhase: WorkflowPhase,
|
|
475
|
-
};
|