doukui 0.0.0-stage → 0.3.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +42 -0
  3. package/README.md +147 -2
  4. package/bin/commands/build.js +178 -0
  5. package/bin/commands/config.js +88 -0
  6. package/bin/commands/help.js +83 -0
  7. package/bin/commands/init.js +194 -0
  8. package/bin/commands/install.js +202 -0
  9. package/bin/commands/interactive.js +352 -0
  10. package/bin/commands/list.js +108 -0
  11. package/bin/commands/loop-server.js +357 -0
  12. package/bin/commands/loop.js +1443 -0
  13. package/bin/commands/migrate.js +120 -0
  14. package/bin/commands/setup-global.js +81 -0
  15. package/bin/commands/status.js +140 -0
  16. package/bin/commands/team-cleanup.js +190 -0
  17. package/bin/commands/validate-config.js +35 -0
  18. package/bin/commands/validate.js +21 -0
  19. package/bin/commands/version.js +22 -0
  20. package/bin/context.js +143 -0
  21. package/bin/doukui.js +216 -0
  22. package/package.json +47 -4
  23. package/plugins/contracts/capabilities.js +268 -0
  24. package/plugins/contracts/checkresult-schema.json +75 -0
  25. package/plugins/contracts/config-schema.json +179 -0
  26. package/plugins/contracts/plugin-interface.js +262 -0
  27. package/plugins/contracts/plugin-schema.json +104 -0
  28. package/plugins/core/hook-session-start/index.js +281 -0
  29. package/plugins/core/hook-session-start/plugin.json +7 -0
  30. package/plugins/core/hook-skill-gate/index.js +661 -0
  31. package/plugins/core/hook-skill-gate/plugin.json +12 -0
  32. package/plugins/core/provider-loop-engine/index.js +1411 -0
  33. package/plugins/core/provider-loop-engine/plugin.json +15 -0
  34. package/plugins/core/provider-memory-store/index.js +510 -0
  35. package/plugins/core/provider-memory-store/plugin.json +9 -0
  36. package/plugins/core/provider-role-registry/index.js +376 -0
  37. package/plugins/core/provider-role-registry/plugin.json +9 -0
  38. package/plugins/core/provider-state-store/index.js +244 -0
  39. package/plugins/core/provider-state-store/plugin.json +9 -0
  40. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +32 -0
  41. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +676 -0
  42. package/plugins/core/provider-watchdog/assets/watchdog.js +754 -0
  43. package/plugins/core/provider-watchdog/index.js +151 -0
  44. package/plugins/core/provider-watchdog/plugin.json +13 -0
  45. package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +214 -0
  46. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +249 -0
  47. package/plugins/core/skill-agent-dispatcher/plugin.json +13 -0
  48. package/plugins/core/skill-agent-dispatcher/roles-reference.md +253 -0
  49. package/plugins/core/skill-agent-dispatcher/skill.md +1291 -0
  50. package/plugins/core/skill-agentic-loop/plugin.json +20 -0
  51. package/plugins/core/skill-agentic-loop/skill.md +588 -0
  52. package/plugins/core/skill-batch-task-creator/plugin.json +15 -0
  53. package/plugins/core/skill-batch-task-creator/skill.md +620 -0
  54. package/plugins/core/skill-checklist/plugin.json +10 -0
  55. package/plugins/core/skill-checklist/skill.md +171 -0
  56. package/plugins/core/skill-completion-report/plugin.json +10 -0
  57. package/plugins/core/skill-completion-report/skill.md +331 -0
  58. package/plugins/core/skill-doukui-plan/plugin.json +15 -0
  59. package/plugins/core/skill-doukui-plan/skill.md +233 -0
  60. package/plugins/core/skill-doukui-sync/plugin.json +10 -0
  61. package/plugins/core/skill-doukui-sync/skill.md +76 -0
  62. package/plugins/core/skill-experience-logger/plugin.json +10 -0
  63. package/plugins/core/skill-experience-logger/skill.md +235 -0
  64. package/plugins/core/skill-human-checkpoint/plugin.json +10 -0
  65. package/plugins/core/skill-human-checkpoint/skill.md +194 -0
  66. package/plugins/core/skill-progress-tracker/plugin.json +10 -0
  67. package/plugins/core/skill-progress-tracker/skill.md +228 -0
  68. package/plugins/core/skill-role-manager/plugin.json +10 -0
  69. package/plugins/core/skill-role-manager/skill.md +252 -0
  70. package/plugins/core/skill-split-work-package/plugin.json +15 -0
  71. package/plugins/core/skill-split-work-package/skill.md +441 -0
  72. package/plugins/core/skill-task-archive/plugin.json +10 -0
  73. package/plugins/core/skill-task-archive/skill.md +116 -0
  74. package/plugins/core/skill-task-creator/plugin.json +15 -0
  75. package/plugins/core/skill-task-creator/skill.md +886 -0
  76. package/plugins/core/skill-team-cleanup/plugin.json +10 -0
  77. package/plugins/core/skill-team-cleanup/skill.md +266 -0
  78. package/plugins/core/skill-watchdog-manager/plugin.json +10 -0
  79. package/plugins/core/skill-watchdog-manager/skill.md +143 -0
  80. package/plugins/core/skill-workflow-orchestrator/plugin.json +13 -0
  81. package/plugins/core/skill-workflow-orchestrator/skill.md +273 -0
  82. package/plugins/core/validator-doc-sync/index.js +248 -0
  83. package/plugins/core/validator-doc-sync/plugin.json +12 -0
  84. package/plugins/core/validator-work-package/index.js +300 -0
  85. package/plugins/core/validator-work-package/plugin.json +12 -0
  86. package/plugins/plugin-registry.json +186 -0
  87. package/plugins/runtime/agent-def-generator.js +150 -0
  88. package/plugins/runtime/audit-logger.js +311 -0
  89. package/plugins/runtime/build-cli.js +89 -0
  90. package/plugins/runtime/checkresult-validator.js +131 -0
  91. package/plugins/runtime/claude-md-injector.js +159 -0
  92. package/plugins/runtime/cleanup-utils.js +293 -0
  93. package/plugins/runtime/config-manager.js +317 -0
  94. package/plugins/runtime/config-validator.js +320 -0
  95. package/plugins/runtime/context-window.js +81 -0
  96. package/plugins/runtime/event-bus.js +207 -0
  97. package/plugins/runtime/executor-claude.js +828 -0
  98. package/plugins/runtime/executor-default.js +448 -0
  99. package/plugins/runtime/executor-local.js +178 -0
  100. package/plugins/runtime/executor-sdk.js +415 -0
  101. package/plugins/runtime/harness-build.js +1037 -0
  102. package/plugins/runtime/hook-dispatcher.js +315 -0
  103. package/plugins/runtime/logger.js +192 -0
  104. package/plugins/runtime/loop-actuator.js +292 -0
  105. package/plugins/runtime/loop-coordinator.js +347 -0
  106. package/plugins/runtime/loop-defaults.js +29 -0
  107. package/plugins/runtime/loop-dispatch-batch.js +247 -0
  108. package/plugins/runtime/loop-executor.js +120 -0
  109. package/plugins/runtime/loop-report.js +327 -0
  110. package/plugins/runtime/loop-server-core.js +750 -0
  111. package/plugins/runtime/loop-snapshot.js +581 -0
  112. package/plugins/runtime/loop-trace.js +242 -0
  113. package/plugins/runtime/loop-worktree.js +404 -0
  114. package/plugins/runtime/manifest-resolver.js +457 -0
  115. package/plugins/runtime/multi-window-coordinator.js +560 -0
  116. package/plugins/runtime/objective-verifier.js +136 -0
  117. package/plugins/runtime/plan-lint.js +100 -0
  118. package/plugins/runtime/plan-reader.js +763 -0
  119. package/plugins/runtime/plugin-loader.js +798 -0
  120. package/plugins/runtime/plugin-trust.js +182 -0
  121. package/plugins/runtime/plugin-validator.js +491 -0
  122. package/plugins/runtime/provider-failover.js +114 -0
  123. package/plugins/runtime/provider-resolver.js +342 -0
  124. package/plugins/runtime/reflection-evaluator.js +545 -0
  125. package/plugins/runtime/resolve-plugin-path.js +297 -0
  126. package/plugins/runtime/safe-path.js +119 -0
  127. package/plugins/runtime/sandbox-context.js +235 -0
  128. package/plugins/runtime/sandbox-manager.js +609 -0
  129. package/plugins/runtime/sandbox-worker.js +215 -0
  130. package/plugins/runtime/self-rescue-ladder.js +38 -0
  131. package/plugins/runtime/settings-merger.js +172 -0
  132. package/plugins/runtime/state-store.js +527 -0
  133. package/plugins/runtime/team-cleanup.js +497 -0
  134. package/plugins/runtime/text-tokenize.js +25 -0
  135. package/plugins/runtime/validator-pipeline.js +475 -0
  136. package/plugins/runtime/yaml-parser.js +692 -0
  137. package/templates/harness-config.yaml +394 -0
@@ -0,0 +1,194 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var cleanupUtils = require('../../plugins/runtime/cleanup-utils');
6
+
7
+ /**
8
+ * Init command - First-time setup: build + generate default config
9
+ * @public
10
+ */
11
+ module.exports = {
12
+ name: 'init',
13
+ description: 'First-time setup (build + config)',
14
+ /**
15
+ * Execute the init command.
16
+ * @public
17
+ * @param {object} ctx - CLI context object
18
+ */
19
+ execute: function (ctx) {
20
+ console.log('[doukui] Initializing...');
21
+ console.log('[doukui] Target project: ' + ctx.targetRoot);
22
+ console.log('[doukui] Package root: ' + ctx.packageRoot);
23
+ console.log('');
24
+
25
+ var hasLegacyStructure = false;
26
+ var cleanupActions = [];
27
+
28
+ // 1. Ensure .claude/ directory exists
29
+ var claudeDir = path.join(ctx.targetRoot, '.claude');
30
+ if (!fs.existsSync(claudeDir)) {
31
+ fs.mkdirSync(claudeDir, { recursive: true });
32
+ console.log('[doukui] Created .claude/ directory');
33
+ }
34
+
35
+ // 2. Ensure .claude/config/ directory exists
36
+ var configDir = ctx.configDir;
37
+ if (!fs.existsSync(configDir)) {
38
+ fs.mkdirSync(configDir, { recursive: true });
39
+ console.log('[doukui] Created .claude/config/ directory');
40
+ }
41
+
42
+ // 3. Copy harness-config.yaml template if not exists
43
+ var targetConfigPath = path.join(configDir, 'harness-config.yaml');
44
+ var templatePath = path.join(ctx.packageRoot, 'templates', 'harness-config.yaml');
45
+
46
+ if (!fs.existsSync(targetConfigPath)) {
47
+ try {
48
+ var content = fs.readFileSync(templatePath, 'utf-8');
49
+ fs.writeFileSync(targetConfigPath, content, 'utf-8');
50
+ console.log('[doukui] Created harness-config.yaml');
51
+ } catch (err) {
52
+ console.error('[doukui] Warning: Failed to copy harness-config.yaml template');
53
+ console.error('[doukui] Error: ' + err.message);
54
+ }
55
+ } else {
56
+ console.log('[doukui] harness-config.yaml already exists, skipping');
57
+ }
58
+
59
+ // 4. Create harness-manifest.json if not exists
60
+ var manifestPath = path.join(claudeDir, 'harness-manifest.json');
61
+ if (!fs.existsSync(manifestPath)) {
62
+ try {
63
+ var ManifestResolver = require('../../plugins/runtime/manifest-resolver');
64
+ var defaultManifest = ManifestResolver.createDefaultManifest(ctx.packageRoot);
65
+ var manifestContent = JSON.stringify(defaultManifest, null, 2);
66
+ fs.writeFileSync(manifestPath, manifestContent + '\n', 'utf-8');
67
+ console.log('[doukui] Created harness-manifest.json');
68
+
69
+ // Print plugin activation summary
70
+ var plugins = defaultManifest.plugins || {};
71
+ var pluginNames = Object.keys(plugins);
72
+ var enabledCount = 0;
73
+ for (var i = 0; i < pluginNames.length; i++) {
74
+ if (plugins[pluginNames[i]].enabled !== false) {
75
+ enabledCount++;
76
+ }
77
+ }
78
+ console.log('[doukui] Plugin activation: ' + enabledCount + ' enabled, ' + (pluginNames.length - enabledCount) + ' disabled');
79
+ } catch (err) {
80
+ console.error('[doukui] Warning: Failed to create harness-manifest.json');
81
+ console.error('[doukui] Error: ' + err.message);
82
+ }
83
+ } else {
84
+ console.log('[doukui] harness-manifest.json already exists, skipping');
85
+ }
86
+
87
+ // 4.5. Create settings.json with hook registration (global mode)
88
+ var builder = ctx.createBuilder();
89
+ // B22: updateSettings may create OR update an existing settings.json.
90
+ // Snapshot existence before the call so the log message is accurate.
91
+ var settingsExistedBefore = false;
92
+ try {
93
+ settingsExistedBefore = fs.existsSync(ctx.settingsPath);
94
+ } catch (_e) { /* ignore — treat as not-existing */ }
95
+ builder.updateSettings(ctx.targetRoot, ctx.packageRoot);
96
+ if (settingsExistedBefore) {
97
+ console.log('[doukui] Updated .claude/settings.json with global hook registration');
98
+ } else {
99
+ console.log('[doukui] Created .claude/settings.json with global hook registration');
100
+ }
101
+
102
+ // 5. Detect and clean up legacy project-level hooks registration
103
+ var settingsPath = ctx.settingsPath;
104
+ if (fs.existsSync(settingsPath)) {
105
+ try {
106
+ var settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
107
+ var result = cleanupUtils.cleanupSettingsHooks(settings);
108
+
109
+ if (result.hadProjectHooks) {
110
+ fs.writeFileSync(settingsPath, JSON.stringify(result.settings, null, 2) + '\n', 'utf-8');
111
+ console.log(ctx.colorize('[doukui] Cleaned up legacy project-level hooks registration', 'yellow'));
112
+ hasLegacyStructure = true;
113
+ cleanupActions.push('Removed project-level hooks from .claude/settings.json');
114
+ }
115
+ } catch (err) {
116
+ // Expected degradation: user's settings.json may be malformed/unreadable.
117
+ // Cleanup is optional (best-effort); do not surface as Error-level noise.
118
+ if (ctx.flags.verbose) {
119
+ console.warn('[doukui] (degraded) Skipped project-level hooks cleanup: ' + err.message);
120
+ }
121
+ }
122
+ }
123
+
124
+ // 6. Detect and clean up legacy project-level skills
125
+ var projectSkillsDir = path.join(claudeDir, 'skills');
126
+ if (fs.existsSync(projectSkillsDir)) {
127
+ try {
128
+ var removedSkills = cleanupUtils.cleanupProjectSkills(projectSkillsDir, ctx.registryPath, ctx.packageRoot);
129
+
130
+ if (removedSkills.length > 0) {
131
+ console.log(ctx.colorize('[doukui] Cleaned up ' + removedSkills.length + ' project-level skills (now available globally)', 'yellow'));
132
+ hasLegacyStructure = true;
133
+ cleanupActions.push('Removed ' + removedSkills.length + ' project-level skills (now available globally)');
134
+
135
+ cleanupUtils.removeEmptyDir(projectSkillsDir);
136
+ if (!fs.existsSync(projectSkillsDir)) {
137
+ console.log('[doukui] Removed empty .claude/skills/ directory');
138
+ }
139
+ }
140
+ } catch (err) {
141
+ // Expected degradation: legacy skills cleanup is best-effort and optional.
142
+ if (ctx.flags.verbose) {
143
+ console.warn('[doukui] (degraded) Skipped project-level skills cleanup: ' + err.message);
144
+ }
145
+ }
146
+ }
147
+
148
+ // 7. Detect and clean up legacy project-level hooks
149
+ var projectHooksDir = path.join(claudeDir, 'hooks');
150
+ if (fs.existsSync(projectHooksDir)) {
151
+ try {
152
+ var removedHooks = cleanupUtils.cleanupProjectHooks(projectHooksDir, ctx.registryPath, ctx.packageRoot);
153
+
154
+ if (removedHooks.length > 0) {
155
+ console.log(ctx.colorize('[doukui] Cleaned up ' + removedHooks.length + ' project-level hooks (now available globally)', 'yellow'));
156
+ hasLegacyStructure = true;
157
+ cleanupActions.push('Removed ' + removedHooks.length + ' project-level hooks (now available globally)');
158
+ }
159
+
160
+ cleanupUtils.removeEmptyDir(projectHooksDir);
161
+ if (!fs.existsSync(projectHooksDir)) {
162
+ console.log('[doukui] Removed empty .claude/hooks/ directory');
163
+ }
164
+ } catch (err) {
165
+ // Expected degradation: legacy hooks dir cleanup is best-effort and optional.
166
+ if (ctx.flags.verbose) {
167
+ console.warn('[doukui] (degraded) Skipped project-level hooks dir cleanup: ' + err.message);
168
+ }
169
+ }
170
+ }
171
+
172
+ // 8. Inject CLAUDE.md plan-mode rules (independent of build)
173
+ builder.injectClaudeMdRules(ctx.targetRoot);
174
+
175
+ // 9. Print migration summary if legacy structure was detected
176
+ if (hasLegacyStructure) {
177
+ console.log('');
178
+ console.log(ctx.colorize('[doukui] === Migration Summary ===', 'cyan'));
179
+ console.log(ctx.colorize('[doukui] Your project has been updated to use global skills/hooks.', 'cyan'));
180
+ console.log('');
181
+ for (var q = 0; q < cleanupActions.length; q++) {
182
+ console.log(' - ' + cleanupActions[q]);
183
+ }
184
+ console.log('');
185
+ console.log(ctx.colorize('[doukui] All doukui skills and hooks are now available globally.', 'green'));
186
+ console.log(ctx.colorize('[doukui] Your project only needs configuration files to use them.', 'green'));
187
+ console.log('');
188
+ }
189
+
190
+ console.log(ctx.colorize('[doukui] Done! Your project is ready to use doukui.', 'green'));
191
+ // B21: explicit success exit to match the exit discipline of other commands.
192
+ ctx.exit(0);
193
+ },
194
+ };
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Install command - Install an external plugin with security confirmation
3
+ * @public
4
+ *
5
+ * When an external plugin (npm/local sourceType) declares capabilities,
6
+ * the user is prompted to confirm before installation proceeds.
7
+ * Non-interactive mode is supported via DOUKUI_ASSUME_YES environment variable.
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ var fs = require('fs');
13
+ var path = require('path');
14
+ var readline = require('readline');
15
+
16
+ /**
17
+ * Known capability names with risk level labels.
18
+ * @type {Object.<string, string>}
19
+ */
20
+ var CAPABILITY_LEVELS = {
21
+ 'filesystem': 'high',
22
+ 'network': 'high',
23
+ 'child_process': 'critical',
24
+ 'env': 'medium',
25
+ };
26
+
27
+ /**
28
+ * Confirm installation of an external plugin.
29
+ *
30
+ * Displays the plugin's declared capabilities and asks the user to confirm.
31
+ * - If capabilities are empty or missing, auto-approves (basic services only).
32
+ * - In non-interactive environments, checks DOUKUI_ASSUME_YES env var.
33
+ * - In interactive mode, prompts with [y/N] and waits for user input.
34
+ *
35
+ * @param {string} pluginName - Name of the plugin being installed
36
+ * @param {object} registryEntry - Registry entry with optional capabilities field
37
+ * @param {object} [options] - Options
38
+ * @param {boolean} [options.isNonInteractive] - Force non-interactive mode
39
+ * @returns {Promise<boolean>} true if user confirms or auto-approved, false if rejected
40
+ */
41
+ async function confirmInstall(pluginName, registryEntry, options) {
42
+ options = options || {};
43
+ var capabilities = registryEntry.capabilities || {};
44
+ var capKeys = Object.keys(capabilities);
45
+
46
+ // No extra capabilities — auto-approve
47
+ if (capKeys.length === 0) {
48
+ console.log('Plugin ' + pluginName + ' declares no extra capabilities (basic services only).');
49
+ return true;
50
+ }
51
+
52
+ // Display capabilities with risk levels
53
+ console.log('');
54
+ console.log('Plugin ' + pluginName + ' declares the following capabilities:');
55
+ for (var i = 0; i < capKeys.length; i++) {
56
+ var cap = capKeys[i];
57
+ var level = CAPABILITY_LEVELS[cap] || 'unknown';
58
+ var detail = capabilities[cap];
59
+ console.log(' - ' + cap + ' (' + level + '): ' + JSON.stringify(detail));
60
+ }
61
+ console.log('');
62
+
63
+ // Non-interactive mode: check DOUKUI_ASSUME_YES
64
+ var isNonInteractive = options.isNonInteractive || !process.stdout.isTTY;
65
+ if (isNonInteractive) {
66
+ if (process.env.DOUKUI_ASSUME_YES === '1' || process.env.DOUKUI_ASSUME_YES === 'true') {
67
+ console.log('DOUKUI_ASSUME_YES is set. Automatically approving installation.');
68
+ return true;
69
+ }
70
+ console.error('Non-interactive mode detected and DOUKUI_ASSUME_YES is not set.');
71
+ console.error('Installation aborted. Set DOUKUI_ASSUME_YES=1 to auto-approve.');
72
+ return false;
73
+ }
74
+
75
+ // Interactive mode: prompt user
76
+ var answer = await promptUser('Confirm installation? [y/N] ');
77
+ var confirmed = answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes';
78
+
79
+ if (!confirmed) {
80
+ console.log('Installation of ' + pluginName + ' cancelled by user.');
81
+ }
82
+
83
+ return confirmed;
84
+ }
85
+
86
+ /**
87
+ * Prompt the user for input via readline.
88
+ *
89
+ * @param {string} question - The prompt text
90
+ * @returns {Promise<string>} User input trimmed
91
+ */
92
+ function promptUser(question) {
93
+ return new Promise(function (resolve) {
94
+ var rl = readline.createInterface({
95
+ input: process.stdin,
96
+ output: process.stdout,
97
+ });
98
+ rl.question(question, function (answer) {
99
+ rl.close();
100
+ resolve((answer || '').trim());
101
+ });
102
+ });
103
+ }
104
+
105
+ /**
106
+ * Install command entry point.
107
+ * Reads a plugin name, resolves its metadata, and runs security confirmation.
108
+ */
109
+ module.exports = {
110
+ name: 'install',
111
+ description: 'Install an external plugin with security review',
112
+ execute: function (ctx) {
113
+ // B1 修复:context 仅提供 ctx.argv(bin/context.js),原代码误用 ctx.args
114
+ // 导致任何调用都恒报 "Plugin name required"。
115
+ var argv = ctx.argv || [];
116
+ var pluginName = argv[0];
117
+
118
+ if (!pluginName) {
119
+ console.error(ctx.colorize('Error: Plugin name required. Usage: doukui install <plugin-name>', 'red'));
120
+ ctx.exit(1);
121
+ return;
122
+ }
123
+
124
+ console.log('[doukui] Installing plugin: ' + pluginName);
125
+
126
+ // Read registry to find the plugin entry
127
+ var registry = ctx.createBuilder()._readRegistry();
128
+ var plugins = registry.plugins || [];
129
+ var entry = null;
130
+ for (var i = 0; i < plugins.length; i++) {
131
+ if (plugins[i].name === pluginName) {
132
+ entry = plugins[i];
133
+ break;
134
+ }
135
+ }
136
+
137
+ if (!entry) {
138
+ console.error(ctx.colorize('Error: Plugin "' + pluginName + '" not found in registry', 'red'));
139
+ ctx.exit(1);
140
+ return;
141
+ }
142
+
143
+ // Core plugins don't need confirmation
144
+ var sourceType = entry.sourceType || 'core';
145
+ if (sourceType === 'core') {
146
+ console.log('[doukui] Core plugin — no security review needed.');
147
+ console.log(ctx.colorize('[doukui] Security review passed: ' + pluginName + ' (already part of the harness build).', 'green'));
148
+ ctx.exit(0);
149
+ return;
150
+ }
151
+
152
+ // External plugin: read plugin.json for capabilities
153
+ var pluginDir;
154
+ try {
155
+ pluginDir = ctx.createBuilder()._resolvePluginDir(entry);
156
+ } catch (err) {
157
+ console.error(ctx.colorize('Error: Could not resolve plugin directory: ' + err.message, 'red'));
158
+ ctx.exit(1);
159
+ return;
160
+ }
161
+
162
+ var metaPath = path.join(pluginDir, 'plugin.json');
163
+ if (!fs.existsSync(metaPath)) {
164
+ console.error(ctx.colorize('Error: plugin.json not found at ' + metaPath, 'red'));
165
+ ctx.exit(1);
166
+ return;
167
+ }
168
+
169
+ var meta;
170
+ try {
171
+ meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8'));
172
+ } catch (err) {
173
+ console.error(ctx.colorize('Error: Invalid plugin.json: ' + err.message, 'red'));
174
+ ctx.exit(1);
175
+ return;
176
+ }
177
+
178
+ // Merge capabilities from plugin.json and registry entry
179
+ var mergedEntry = {
180
+ capabilities: meta.capabilities || entry.capabilities || {},
181
+ };
182
+
183
+ confirmInstall(pluginName, mergedEntry).then(function (confirmed) {
184
+ if (confirmed) {
185
+ // 注意:本命令目前只做能力声明审查,不执行实际的文件复制/registry 变更/build。
186
+ // 插件需另行通过 plugin-registry.json 注册并跑 `doukui build` 才会生效。
187
+ console.log(ctx.colorize('[doukui] Security review passed for ' + pluginName + '.', 'green'));
188
+ console.log('[doukui] Note: this command reviews capabilities only — add the plugin to plugin-registry.json and run `doukui build` to make it active.');
189
+ ctx.exit(0);
190
+ } else {
191
+ ctx.exit(1);
192
+ }
193
+ }).catch(function (err) {
194
+ console.error(ctx.colorize('Error during installation: ' + err.message, 'red'));
195
+ ctx.exit(1);
196
+ });
197
+ },
198
+ };
199
+
200
+ // Export confirmInstall for testing
201
+ module.exports.confirmInstall = confirmInstall;
202
+ module.exports.CAPABILITY_LEVELS = CAPABILITY_LEVELS;