doukui 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.en.md +42 -0
- package/README.md +147 -2
- package/bin/commands/build.js +178 -0
- package/bin/commands/config.js +88 -0
- package/bin/commands/help.js +83 -0
- package/bin/commands/init.js +194 -0
- package/bin/commands/install.js +202 -0
- package/bin/commands/interactive.js +352 -0
- package/bin/commands/list.js +108 -0
- package/bin/commands/loop-server.js +357 -0
- package/bin/commands/loop.js +1398 -0
- package/bin/commands/migrate.js +120 -0
- package/bin/commands/setup-global.js +81 -0
- package/bin/commands/status.js +140 -0
- package/bin/commands/team-cleanup.js +190 -0
- package/bin/commands/validate-config.js +35 -0
- package/bin/commands/validate.js +21 -0
- package/bin/commands/version.js +22 -0
- package/bin/context.js +143 -0
- package/bin/doukui.js +216 -0
- package/package.json +47 -4
- package/plugins/contracts/capabilities.js +268 -0
- package/plugins/contracts/checkresult-schema.json +75 -0
- package/plugins/contracts/config-schema.json +179 -0
- package/plugins/contracts/plugin-interface.js +262 -0
- package/plugins/contracts/plugin-schema.json +104 -0
- package/plugins/core/hook-session-start/index.js +281 -0
- package/plugins/core/hook-session-start/plugin.json +7 -0
- package/plugins/core/hook-skill-gate/index.js +661 -0
- package/plugins/core/hook-skill-gate/plugin.json +12 -0
- package/plugins/core/provider-loop-engine/index.js +1397 -0
- package/plugins/core/provider-loop-engine/plugin.json +15 -0
- package/plugins/core/provider-memory-store/index.js +510 -0
- package/plugins/core/provider-memory-store/plugin.json +9 -0
- package/plugins/core/provider-role-registry/index.js +376 -0
- package/plugins/core/provider-role-registry/plugin.json +9 -0
- package/plugins/core/provider-state-store/index.js +244 -0
- package/plugins/core/provider-state-store/plugin.json +9 -0
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +32 -0
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +676 -0
- package/plugins/core/provider-watchdog/assets/watchdog.js +754 -0
- package/plugins/core/provider-watchdog/index.js +151 -0
- package/plugins/core/provider-watchdog/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +214 -0
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +249 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +253 -0
- package/plugins/core/skill-agent-dispatcher/skill.md +1291 -0
- package/plugins/core/skill-agentic-loop/plugin.json +20 -0
- package/plugins/core/skill-agentic-loop/skill.md +572 -0
- package/plugins/core/skill-batch-task-creator/plugin.json +15 -0
- package/plugins/core/skill-batch-task-creator/skill.md +620 -0
- package/plugins/core/skill-checklist/plugin.json +10 -0
- package/plugins/core/skill-checklist/skill.md +171 -0
- package/plugins/core/skill-completion-report/plugin.json +10 -0
- package/plugins/core/skill-completion-report/skill.md +331 -0
- package/plugins/core/skill-doukui-plan/plugin.json +15 -0
- package/plugins/core/skill-doukui-plan/skill.md +233 -0
- package/plugins/core/skill-doukui-sync/plugin.json +10 -0
- package/plugins/core/skill-doukui-sync/skill.md +76 -0
- package/plugins/core/skill-experience-logger/plugin.json +10 -0
- package/plugins/core/skill-experience-logger/skill.md +235 -0
- package/plugins/core/skill-human-checkpoint/plugin.json +10 -0
- package/plugins/core/skill-human-checkpoint/skill.md +194 -0
- package/plugins/core/skill-progress-tracker/plugin.json +10 -0
- package/plugins/core/skill-progress-tracker/skill.md +228 -0
- package/plugins/core/skill-role-manager/plugin.json +10 -0
- package/plugins/core/skill-role-manager/skill.md +252 -0
- package/plugins/core/skill-split-work-package/plugin.json +15 -0
- package/plugins/core/skill-split-work-package/skill.md +441 -0
- package/plugins/core/skill-task-archive/plugin.json +10 -0
- package/plugins/core/skill-task-archive/skill.md +116 -0
- package/plugins/core/skill-task-creator/plugin.json +15 -0
- package/plugins/core/skill-task-creator/skill.md +886 -0
- package/plugins/core/skill-team-cleanup/plugin.json +10 -0
- package/plugins/core/skill-team-cleanup/skill.md +266 -0
- package/plugins/core/skill-watchdog-manager/plugin.json +10 -0
- package/plugins/core/skill-watchdog-manager/skill.md +143 -0
- package/plugins/core/skill-workflow-orchestrator/plugin.json +13 -0
- package/plugins/core/skill-workflow-orchestrator/skill.md +273 -0
- package/plugins/core/validator-doc-sync/index.js +248 -0
- package/plugins/core/validator-doc-sync/plugin.json +12 -0
- package/plugins/core/validator-work-package/index.js +300 -0
- package/plugins/core/validator-work-package/plugin.json +12 -0
- package/plugins/plugin-registry.json +186 -0
- package/plugins/runtime/agent-def-generator.js +150 -0
- package/plugins/runtime/audit-logger.js +311 -0
- package/plugins/runtime/build-cli.js +89 -0
- package/plugins/runtime/checkresult-validator.js +131 -0
- package/plugins/runtime/claude-md-injector.js +159 -0
- package/plugins/runtime/cleanup-utils.js +293 -0
- package/plugins/runtime/config-manager.js +317 -0
- package/plugins/runtime/config-validator.js +320 -0
- package/plugins/runtime/context-window.js +81 -0
- package/plugins/runtime/event-bus.js +207 -0
- package/plugins/runtime/executor-claude.js +828 -0
- package/plugins/runtime/executor-default.js +448 -0
- package/plugins/runtime/executor-local.js +178 -0
- package/plugins/runtime/executor-sdk.js +390 -0
- package/plugins/runtime/harness-build.js +1037 -0
- package/plugins/runtime/hook-dispatcher.js +315 -0
- package/plugins/runtime/logger.js +192 -0
- package/plugins/runtime/loop-actuator.js +292 -0
- package/plugins/runtime/loop-coordinator.js +347 -0
- package/plugins/runtime/loop-defaults.js +29 -0
- package/plugins/runtime/loop-dispatch-batch.js +247 -0
- package/plugins/runtime/loop-executor.js +120 -0
- package/plugins/runtime/loop-report.js +327 -0
- package/plugins/runtime/loop-server-core.js +750 -0
- package/plugins/runtime/loop-snapshot.js +581 -0
- package/plugins/runtime/loop-trace.js +242 -0
- package/plugins/runtime/loop-worktree.js +404 -0
- package/plugins/runtime/manifest-resolver.js +457 -0
- package/plugins/runtime/multi-window-coordinator.js +560 -0
- package/plugins/runtime/objective-verifier.js +136 -0
- package/plugins/runtime/plan-reader.js +763 -0
- package/plugins/runtime/plugin-loader.js +798 -0
- package/plugins/runtime/plugin-trust.js +182 -0
- package/plugins/runtime/plugin-validator.js +491 -0
- package/plugins/runtime/provider-failover.js +114 -0
- package/plugins/runtime/provider-resolver.js +342 -0
- package/plugins/runtime/reflection-evaluator.js +540 -0
- package/plugins/runtime/resolve-plugin-path.js +297 -0
- package/plugins/runtime/safe-path.js +119 -0
- package/plugins/runtime/sandbox-context.js +235 -0
- package/plugins/runtime/sandbox-manager.js +609 -0
- package/plugins/runtime/sandbox-worker.js +215 -0
- package/plugins/runtime/settings-merger.js +172 -0
- package/plugins/runtime/state-store.js +527 -0
- package/plugins/runtime/team-cleanup.js +497 -0
- package/plugins/runtime/text-tokenize.js +25 -0
- package/plugins/runtime/validator-pipeline.js +475 -0
- package/plugins/runtime/yaml-parser.js +692 -0
- package/templates/harness-config.yaml +388 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ManifestResolver - Project-level plugin selection system
|
|
3
|
+
*
|
|
4
|
+
* Manages project-specific plugin overrides via .claude/harness-manifest.json.
|
|
5
|
+
* Projects can override the global plugin-registry.json enabled status,
|
|
6
|
+
* and also register external plugins not present in the global registry.
|
|
7
|
+
*
|
|
8
|
+
* Rules:
|
|
9
|
+
* - Manifest only records overrides (plugins where project != global)
|
|
10
|
+
* - Unlisted plugins use global registry defaults
|
|
11
|
+
* - New plugins appear automatically unless explicitly disabled
|
|
12
|
+
* - External plugins (not in global registry) can be declared via manifest
|
|
13
|
+
* with sourceType and source fields for path resolution
|
|
14
|
+
*
|
|
15
|
+
* Manifest format:
|
|
16
|
+
* {
|
|
17
|
+
* "version": "1.0.0",
|
|
18
|
+
* "doukuiVersion": "0.0.19",
|
|
19
|
+
* "plugins": {
|
|
20
|
+
* "skill-task-creator": { "enabled": true },
|
|
21
|
+
* "hook-skill-gate": { "enabled": false },
|
|
22
|
+
* "my-external-plugin": {
|
|
23
|
+
* "enabled": true,
|
|
24
|
+
* "sourceType": "npm",
|
|
25
|
+
* "source": "doukui-plugin-my-external"
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
'use strict';
|
|
32
|
+
|
|
33
|
+
var fs = require('fs');
|
|
34
|
+
var path = require('path');
|
|
35
|
+
|
|
36
|
+
// Default manifest version
|
|
37
|
+
var MANIFEST_VERSION = '1.0.0';
|
|
38
|
+
|
|
39
|
+
// Read package.json for version
|
|
40
|
+
var packageJsonPath = path.resolve(__dirname, '../../package.json');
|
|
41
|
+
// B14: previous fallback was a stale hardcoded '0.0.19' that would be written
|
|
42
|
+
// to generated manifests if package.json read failed. Use '0.0.0' so a failed
|
|
43
|
+
// read is OBVIOUSLY wrong (rather than silently writing a misleading semver),
|
|
44
|
+
// and surface a warning so operators notice.
|
|
45
|
+
var DOUKUI_HARNESS_VERSION = '0.0.0';
|
|
46
|
+
try {
|
|
47
|
+
var pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
48
|
+
DOUKUI_HARNESS_VERSION = pkg.version || DOUKUI_HARNESS_VERSION;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// B14: explicit warning — a silent fallback to a stale version is worse
|
|
51
|
+
// than an obvious '0.0.0' that signals the read failed.
|
|
52
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
53
|
+
console.warn('[manifest-resolver] Could not read package.json for version (' +
|
|
54
|
+
e.message + '); falling back to "0.0.0".');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Read the global plugin registry.
|
|
60
|
+
* @public
|
|
61
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
62
|
+
* @returns {object} Parsed registry object
|
|
63
|
+
*/
|
|
64
|
+
function readGlobalRegistry(packageRoot) {
|
|
65
|
+
var registryPath = path.join(packageRoot, 'plugins', 'plugin-registry.json');
|
|
66
|
+
|
|
67
|
+
if (!fs.existsSync(registryPath)) {
|
|
68
|
+
return { version: '1.0.0', plugins: [] };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
var content = fs.readFileSync(registryPath, 'utf-8');
|
|
73
|
+
return JSON.parse(content);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return { version: '1.0.0', plugins: [] };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Read the project manifest file.
|
|
81
|
+
* @public
|
|
82
|
+
* @param {string} targetRoot - Target project root directory
|
|
83
|
+
* @returns {object|null} Parsed manifest object or null if not exists
|
|
84
|
+
*/
|
|
85
|
+
function readProjectManifest(targetRoot) {
|
|
86
|
+
var manifestPath = path.join(targetRoot, '.claude', 'harness-manifest.json');
|
|
87
|
+
|
|
88
|
+
if (!fs.existsSync(manifestPath)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
var content = fs.readFileSync(manifestPath, 'utf-8');
|
|
94
|
+
return JSON.parse(content);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
// Invalid manifest, treat as missing
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Resolve effective plugin list by merging global registry with project manifest.
|
|
103
|
+
* Project manifest overrides take precedence.
|
|
104
|
+
*
|
|
105
|
+
* @public
|
|
106
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
107
|
+
* @param {string} targetRoot - Target project root directory
|
|
108
|
+
* @returns {object} Registry object with merged plugin states
|
|
109
|
+
*/
|
|
110
|
+
function resolveEffectivePlugins(packageRoot, targetRoot) {
|
|
111
|
+
var globalRegistry = readGlobalRegistry(packageRoot);
|
|
112
|
+
var projectManifest = readProjectManifest(targetRoot);
|
|
113
|
+
|
|
114
|
+
// If no manifest, return global registry as-is (backward compatibility)
|
|
115
|
+
if (!projectManifest || !projectManifest.plugins) {
|
|
116
|
+
return globalRegistry;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Create a copy of global plugins
|
|
120
|
+
var mergedPlugins = [];
|
|
121
|
+
var globalPlugins = globalRegistry.plugins || [];
|
|
122
|
+
|
|
123
|
+
// Build map of global plugins by name for quick lookup
|
|
124
|
+
var globalMap = {};
|
|
125
|
+
for (var i = 0; i < globalPlugins.length; i++) {
|
|
126
|
+
var p = globalPlugins[i];
|
|
127
|
+
globalMap[p.name] = p;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Process all global plugins with manifest overrides
|
|
131
|
+
for (var j = 0; j < globalPlugins.length; j++) {
|
|
132
|
+
var globalPlugin = globalPlugins[j];
|
|
133
|
+
var pluginName = globalPlugin.name;
|
|
134
|
+
|
|
135
|
+
// Create merged entry (start with global)
|
|
136
|
+
var merged = {
|
|
137
|
+
name: globalPlugin.name,
|
|
138
|
+
source: globalPlugin.source,
|
|
139
|
+
sourceType: globalPlugin.sourceType || 'core',
|
|
140
|
+
enabled: globalPlugin.enabled,
|
|
141
|
+
config: globalPlugin.config || {}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Apply manifest override if exists
|
|
145
|
+
if (projectManifest.plugins[pluginName]) {
|
|
146
|
+
var override = projectManifest.plugins[pluginName];
|
|
147
|
+
if (typeof override.enabled === 'boolean') {
|
|
148
|
+
merged.enabled = override.enabled;
|
|
149
|
+
}
|
|
150
|
+
if (override.config) {
|
|
151
|
+
merged.config = override.config;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
mergedPlugins.push(merged);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Note: New plugins in global registry will appear automatically
|
|
159
|
+
// because we iterate over all globalPlugins above.
|
|
160
|
+
// Only explicitly disabled plugins in manifest are overridden.
|
|
161
|
+
|
|
162
|
+
// Merge external plugins from manifest (plugins not in global registry)
|
|
163
|
+
var manifestPluginNames = Object.keys(projectManifest.plugins);
|
|
164
|
+
for (var k = 0; k < manifestPluginNames.length; k++) {
|
|
165
|
+
var externalName = manifestPluginNames[k];
|
|
166
|
+
|
|
167
|
+
// Skip if already in global registry (already merged above)
|
|
168
|
+
if (globalMap[externalName]) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var externalEntry = projectManifest.plugins[externalName];
|
|
173
|
+
|
|
174
|
+
// Build a complete plugin entry for the external plugin
|
|
175
|
+
var externalPlugin = {
|
|
176
|
+
name: externalName,
|
|
177
|
+
source: externalEntry.source || externalName,
|
|
178
|
+
sourceType: externalEntry.sourceType || 'local',
|
|
179
|
+
enabled: externalEntry.enabled !== false,
|
|
180
|
+
config: externalEntry.config || {}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
mergedPlugins.push(externalPlugin);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
version: globalRegistry.version,
|
|
188
|
+
plugins: mergedPlugins
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Write a project manifest file.
|
|
194
|
+
* @public
|
|
195
|
+
* @param {string} targetRoot - Target project root directory
|
|
196
|
+
* @param {object} manifest - Manifest object to write
|
|
197
|
+
* @returns {boolean} Success status
|
|
198
|
+
*/
|
|
199
|
+
function writeProjectManifest(targetRoot, manifest) {
|
|
200
|
+
var claudeDir = path.join(targetRoot, '.claude');
|
|
201
|
+
var manifestPath = path.join(claudeDir, 'harness-manifest.json');
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
// Ensure .claude directory exists
|
|
205
|
+
if (!fs.existsSync(claudeDir)) {
|
|
206
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Write manifest with proper formatting
|
|
210
|
+
manifest.version = manifest.version || MANIFEST_VERSION;
|
|
211
|
+
manifest.doukuiVersion = manifest.doukuiVersion || DOUKUI_HARNESS_VERSION;
|
|
212
|
+
|
|
213
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf-8');
|
|
214
|
+
return true;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Create a default manifest from the global registry.
|
|
222
|
+
* Only includes plugins that differ from global defaults (for now, all enabled).
|
|
223
|
+
*
|
|
224
|
+
* @public
|
|
225
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
226
|
+
* @returns {object} Default manifest object
|
|
227
|
+
*/
|
|
228
|
+
function createDefaultManifest(packageRoot) {
|
|
229
|
+
var globalRegistry = readGlobalRegistry(packageRoot);
|
|
230
|
+
var plugins = globalRegistry.plugins || [];
|
|
231
|
+
|
|
232
|
+
var manifestPlugins = {};
|
|
233
|
+
|
|
234
|
+
// By default, all plugins are enabled (inherit global state)
|
|
235
|
+
// Only record if we want to override (for now, record all for clarity)
|
|
236
|
+
for (var i = 0; i < plugins.length; i++) {
|
|
237
|
+
var p = plugins[i];
|
|
238
|
+
manifestPlugins[p.name] = {
|
|
239
|
+
enabled: (p.enabled !== false)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
version: MANIFEST_VERSION,
|
|
245
|
+
doukuiVersion: DOUKUI_HARNESS_VERSION,
|
|
246
|
+
plugins: manifestPlugins
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Update a single plugin's enabled status in the project manifest.
|
|
252
|
+
* Creates or updates manifest as needed.
|
|
253
|
+
*
|
|
254
|
+
* @public
|
|
255
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
256
|
+
* @param {string} targetRoot - Target project root directory
|
|
257
|
+
* @param {string} pluginName - Name of the plugin to update
|
|
258
|
+
* @param {boolean} enabled - New enabled status
|
|
259
|
+
* @returns {boolean} Success status
|
|
260
|
+
*/
|
|
261
|
+
function updatePluginInManifest(packageRoot, targetRoot, pluginName, enabled) {
|
|
262
|
+
var manifest = readProjectManifest(targetRoot);
|
|
263
|
+
|
|
264
|
+
// If no manifest exists, create default first
|
|
265
|
+
if (!manifest) {
|
|
266
|
+
manifest = createDefaultManifest(packageRoot);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Ensure plugins object exists
|
|
270
|
+
if (!manifest.plugins) {
|
|
271
|
+
manifest.plugins = {};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Get global default for this plugin
|
|
275
|
+
var globalRegistry = readGlobalRegistry(packageRoot);
|
|
276
|
+
var globalPlugins = globalRegistry.plugins || [];
|
|
277
|
+
var globalPlugin = null;
|
|
278
|
+
for (var i = 0; i < globalPlugins.length; i++) {
|
|
279
|
+
if (globalPlugins[i].name === pluginName) {
|
|
280
|
+
globalPlugin = globalPlugins[i];
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// If plugin not found in global registry, it may be an external plugin.
|
|
286
|
+
// Allow registering external plugins in the manifest.
|
|
287
|
+
if (!globalPlugin) {
|
|
288
|
+
// External plugin: ensure the entry exists in manifest with required fields
|
|
289
|
+
if (!manifest.plugins[pluginName]) {
|
|
290
|
+
manifest.plugins[pluginName] = { enabled: enabled };
|
|
291
|
+
} else {
|
|
292
|
+
manifest.plugins[pluginName].enabled = enabled;
|
|
293
|
+
}
|
|
294
|
+
// Update version
|
|
295
|
+
manifest.doukuiVersion = DOUKUI_HARNESS_VERSION;
|
|
296
|
+
return writeProjectManifest(targetRoot, manifest);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
var globalDefault = (globalPlugin.enabled !== false);
|
|
300
|
+
|
|
301
|
+
// If new status matches global default, remove from manifest (use default)
|
|
302
|
+
if (enabled === globalDefault) {
|
|
303
|
+
delete manifest.plugins[pluginName];
|
|
304
|
+
} else {
|
|
305
|
+
// Override global default
|
|
306
|
+
manifest.plugins[pluginName] = { enabled: enabled };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Update version
|
|
310
|
+
manifest.doukuiVersion = DOUKUI_HARNESS_VERSION;
|
|
311
|
+
|
|
312
|
+
return writeProjectManifest(targetRoot, manifest);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Register an external plugin in the project manifest.
|
|
317
|
+
* This is the primary API for `doukui install` to add external plugins.
|
|
318
|
+
*
|
|
319
|
+
* If the plugin is already registered, its entry is updated.
|
|
320
|
+
* If the plugin exists in the global registry, this still works but
|
|
321
|
+
* log a note that it is overriding a core plugin.
|
|
322
|
+
*
|
|
323
|
+
* @public
|
|
324
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
325
|
+
* @param {string} targetRoot - Target project root directory
|
|
326
|
+
* @param {string} pluginName - Name of the external plugin
|
|
327
|
+
* @param {object} options - Plugin registration options
|
|
328
|
+
* @param {string} [options.sourceType='local'] - Source type: 'npm' or 'local'
|
|
329
|
+
* @param {string} [options.source] - Source identifier (npm package name or path)
|
|
330
|
+
* @param {boolean} [options.enabled=true] - Initial enabled status
|
|
331
|
+
* @param {object} [options.config={}] - Plugin configuration
|
|
332
|
+
* @returns {boolean} Success status
|
|
333
|
+
*/
|
|
334
|
+
function registerExternalPlugin(packageRoot, targetRoot, pluginName, options) {
|
|
335
|
+
options = options || {};
|
|
336
|
+
|
|
337
|
+
var manifest = readProjectManifest(targetRoot);
|
|
338
|
+
|
|
339
|
+
// If no manifest exists, create default first
|
|
340
|
+
if (!manifest) {
|
|
341
|
+
manifest = createDefaultManifest(packageRoot);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Ensure plugins object exists
|
|
345
|
+
if (!manifest.plugins) {
|
|
346
|
+
manifest.plugins = {};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Build the manifest entry
|
|
350
|
+
manifest.plugins[pluginName] = {
|
|
351
|
+
enabled: options.enabled !== false,
|
|
352
|
+
sourceType: options.sourceType || 'local',
|
|
353
|
+
source: options.source || pluginName,
|
|
354
|
+
config: options.config || {}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// Update version
|
|
358
|
+
manifest.doukuiVersion = DOUKUI_HARNESS_VERSION;
|
|
359
|
+
|
|
360
|
+
return writeProjectManifest(targetRoot, manifest);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Unregister an external plugin from the project manifest.
|
|
365
|
+
* Only removes plugins that are not in the global registry.
|
|
366
|
+
* Core plugins can be disabled but not removed via this API.
|
|
367
|
+
*
|
|
368
|
+
* @public
|
|
369
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
370
|
+
* @param {string} targetRoot - Target project root directory
|
|
371
|
+
* @param {string} pluginName - Name of the plugin to unregister
|
|
372
|
+
* @returns {boolean} Success status (false if plugin is a core plugin or not found)
|
|
373
|
+
*/
|
|
374
|
+
function unregisterExternalPlugin(packageRoot, targetRoot, pluginName) {
|
|
375
|
+
var manifest = readProjectManifest(targetRoot);
|
|
376
|
+
if (!manifest || !manifest.plugins || !manifest.plugins[pluginName]) {
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Check if this is a core plugin (exists in global registry)
|
|
381
|
+
var globalRegistry = readGlobalRegistry(packageRoot);
|
|
382
|
+
var globalPlugins = globalRegistry.plugins || [];
|
|
383
|
+
var isCore = false;
|
|
384
|
+
for (var i = 0; i < globalPlugins.length; i++) {
|
|
385
|
+
if (globalPlugins[i].name === pluginName) {
|
|
386
|
+
isCore = true;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (isCore) {
|
|
392
|
+
// Core plugins can only be disabled, not removed
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
delete manifest.plugins[pluginName];
|
|
397
|
+
manifest.doukuiVersion = DOUKUI_HARNESS_VERSION;
|
|
398
|
+
|
|
399
|
+
return writeProjectManifest(targetRoot, manifest);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* List all external plugins in the project manifest
|
|
404
|
+
* (plugins that are NOT in the global registry).
|
|
405
|
+
*
|
|
406
|
+
* @public
|
|
407
|
+
* @param {string} packageRoot - Root directory of doukui package
|
|
408
|
+
* @param {string} targetRoot - Target project root directory
|
|
409
|
+
* @returns {object[]} Array of external plugin entries with name, sourceType, source, enabled, config
|
|
410
|
+
*/
|
|
411
|
+
function listExternalPlugins(packageRoot, targetRoot) {
|
|
412
|
+
var manifest = readProjectManifest(targetRoot);
|
|
413
|
+
if (!manifest || !manifest.plugins) {
|
|
414
|
+
return [];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
var globalRegistry = readGlobalRegistry(packageRoot);
|
|
418
|
+
var globalPlugins = globalRegistry.plugins || [];
|
|
419
|
+
var globalNames = {};
|
|
420
|
+
for (var i = 0; i < globalPlugins.length; i++) {
|
|
421
|
+
globalNames[globalPlugins[i].name] = true;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
var externalPlugins = [];
|
|
425
|
+
var names = Object.keys(manifest.plugins);
|
|
426
|
+
for (var j = 0; j < names.length; j++) {
|
|
427
|
+
var name = names[j];
|
|
428
|
+
if (!globalNames[name]) {
|
|
429
|
+
var entry = manifest.plugins[name];
|
|
430
|
+
externalPlugins.push({
|
|
431
|
+
name: name,
|
|
432
|
+
sourceType: entry.sourceType || 'local',
|
|
433
|
+
source: entry.source || name,
|
|
434
|
+
enabled: entry.enabled !== false,
|
|
435
|
+
config: entry.config || {}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return externalPlugins;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// ---------------------------------------------------------------------------
|
|
444
|
+
// Module exports
|
|
445
|
+
// ---------------------------------------------------------------------------
|
|
446
|
+
|
|
447
|
+
module.exports = {
|
|
448
|
+
readGlobalRegistry: readGlobalRegistry,
|
|
449
|
+
readProjectManifest: readProjectManifest,
|
|
450
|
+
resolveEffectivePlugins: resolveEffectivePlugins,
|
|
451
|
+
writeProjectManifest: writeProjectManifest,
|
|
452
|
+
createDefaultManifest: createDefaultManifest,
|
|
453
|
+
updatePluginInManifest: updatePluginInManifest,
|
|
454
|
+
registerExternalPlugin: registerExternalPlugin,
|
|
455
|
+
unregisterExternalPlugin: unregisterExternalPlugin,
|
|
456
|
+
listExternalPlugins: listExternalPlugins
|
|
457
|
+
};
|