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,120 @@
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
+ * Migrate command - Migrate legacy project structure to global setup
9
+ * @public
10
+ */
11
+ module.exports = {
12
+ name: 'migrate',
13
+ description: 'Migrate legacy project structure to global setup',
14
+ /**
15
+ * Execute the migrate command.
16
+ * @public
17
+ * @param {object} ctx - CLI context object
18
+ */
19
+ execute: function (ctx) {
20
+ console.log(ctx.colorize('[doukui] Migrating legacy project structure...', 'cyan'));
21
+ console.log('[doukui] Target project: ' + ctx.targetRoot);
22
+ console.log('');
23
+
24
+ var hasLegacyStructure = false;
25
+ var cleanupActions = [];
26
+
27
+ // 1. Detect and clean up legacy project-level hooks registration
28
+ var settingsPath = ctx.settingsPath;
29
+ if (fs.existsSync(settingsPath)) {
30
+ try {
31
+ var settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
32
+ var result = cleanupUtils.cleanupSettingsHooks(settings);
33
+
34
+ if (result.hadProjectHooks) {
35
+ fs.writeFileSync(settingsPath, JSON.stringify(result.settings, null, 2) + '\n', 'utf-8');
36
+ console.log(ctx.colorize('[doukui] Removed project-level hooks from settings.json', 'yellow'));
37
+ hasLegacyStructure = true;
38
+ cleanupActions.push('Removed project-level hooks');
39
+ }
40
+ } catch (err) {
41
+ // Expected degradation: user's settings.json may be malformed/unreadable.
42
+ // Hook cleanup is optional (best-effort); do not surface as Error-level noise.
43
+ if (ctx.flags.verbose) {
44
+ console.warn('[doukui] (degraded) Skipped project-level hooks cleanup: ' + err.message);
45
+ }
46
+ }
47
+ }
48
+
49
+ // 2. Detect and clean up legacy project-level skills
50
+ var projectSkillsDir = path.join(ctx.targetRoot, '.claude', 'skills');
51
+ if (fs.existsSync(projectSkillsDir)) {
52
+ try {
53
+ var removedSkills = cleanupUtils.cleanupProjectSkills(projectSkillsDir, ctx.registryPath, ctx.packageRoot);
54
+
55
+ if (removedSkills.length > 0) {
56
+ console.log(ctx.colorize('[doukui] Removed ' + removedSkills.length + ' project-level skills (now available globally)', 'yellow'));
57
+ hasLegacyStructure = true;
58
+ cleanupActions.push('Removed ' + removedSkills.length + ' project-level skills');
59
+
60
+ cleanupUtils.removeEmptyDir(projectSkillsDir);
61
+ if (!fs.existsSync(projectSkillsDir)) {
62
+ console.log('[doukui] Removed empty .claude/skills/ directory');
63
+ }
64
+ }
65
+ } catch (err) {
66
+ // Expected degradation: legacy skills cleanup is best-effort and optional.
67
+ if (ctx.flags.verbose) {
68
+ console.warn('[doukui] (degraded) Skipped project-level skills cleanup: ' + err.message);
69
+ }
70
+ }
71
+ }
72
+
73
+ // 3. Detect and clean up legacy project-level hooks
74
+ var projectHooksDir = path.join(ctx.targetRoot, '.claude', 'hooks');
75
+ if (fs.existsSync(projectHooksDir)) {
76
+ try {
77
+ var removedHooks = cleanupUtils.cleanupProjectHooks(projectHooksDir, ctx.registryPath, ctx.packageRoot);
78
+
79
+ if (removedHooks.length > 0) {
80
+ console.log(ctx.colorize('[doukui] Removed ' + removedHooks.length + ' project-level hooks (now available globally)', 'yellow'));
81
+ hasLegacyStructure = true;
82
+ cleanupActions.push('Removed ' + removedHooks.length + ' project-level hooks');
83
+
84
+ cleanupUtils.removeEmptyDir(projectHooksDir);
85
+ if (!fs.existsSync(projectHooksDir)) {
86
+ console.log('[doukui] Removed empty .claude/hooks/ directory');
87
+ }
88
+ }
89
+ } catch (err) {
90
+ // Expected degradation: legacy hooks dir cleanup is best-effort and optional.
91
+ if (ctx.flags.verbose) {
92
+ console.warn('[doukui] (degraded) Skipped project-level hooks dir cleanup: ' + err.message);
93
+ }
94
+ }
95
+ }
96
+
97
+ // 4. Inject CLAUDE.md plan-mode rules
98
+ var builder = ctx.createBuilder();
99
+ builder.injectClaudeMdRules(ctx.targetRoot);
100
+
101
+ // 5. Print migration summary
102
+ if (!hasLegacyStructure) {
103
+ console.log(ctx.colorize('[doukui] No legacy structure found. Project is already using global setup.', 'green'));
104
+ } else {
105
+ console.log('');
106
+ console.log(ctx.colorize('[doukui] === Migration Complete ===', 'cyan'));
107
+ console.log('');
108
+ for (var q = 0; q < cleanupActions.length; q++) {
109
+ console.log(' - ' + cleanupActions[q]);
110
+ }
111
+ console.log('');
112
+ console.log(ctx.colorize('[doukui] All doukui skills and hooks are now available globally.', 'green'));
113
+ console.log(ctx.colorize('[doukui] Your project only needs configuration files to use them.', 'green'));
114
+ console.log('');
115
+ }
116
+
117
+ console.log(ctx.colorize('[doukui] Done! Your project is ready to use doukui.', 'green'));
118
+ ctx.exit(0);
119
+ },
120
+ };
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var os = require('os');
6
+ var HarnessBuild = require('../../plugins/runtime/harness-build');
7
+
8
+ /**
9
+ * Setup-global command - Install global skills to ~/.claude/skills/
10
+ * @public
11
+ */
12
+ module.exports = {
13
+ name: 'setup-global',
14
+ description: 'Install global skills to ~/.claude/skills/',
15
+ /**
16
+ * Execute the setup-global command.
17
+ * @public
18
+ * @param {object} ctx - CLI context object
19
+ */
20
+ execute: function (ctx) {
21
+ // B16: os.homedir() is the correct cross-platform home resolution.
22
+ // The previous `process.env.HOME || USERPROFILE` returns a Unix-style
23
+ // path under Git Bash on Windows (HOME=/c/Users/...), which breaks the
24
+ // fs APIs expecting a Windows path. os.homedir() always returns the
25
+ // platform-native path.
26
+ var homeDir = os.homedir();
27
+ if (!homeDir) {
28
+ console.error(ctx.colorize('Error: Cannot determine home directory', 'red'));
29
+ ctx.exit(1);
30
+ return; // B16: exit doesn't halt flow by itself; guard the rest.
31
+ }
32
+
33
+ console.log(ctx.colorize('[doukui] Installing global skills and hooks...', 'cyan'));
34
+ console.log('[doukui] Home directory: ' + homeDir);
35
+ console.log('[doukui] Package root: ' + ctx.packageRoot);
36
+ console.log('');
37
+
38
+ // Create a global builder with home directory as target
39
+ var globalBuilder = new HarnessBuild({
40
+ targetRoot: homeDir,
41
+ packageRoot: ctx.packageRoot,
42
+ registryPath: ctx.registryPath,
43
+ pluginsDir: ctx.pluginsDir,
44
+ outputSkillsDir: path.join(homeDir, '.claude', 'skills'),
45
+ outputHooksDir: path.join(homeDir, '.claude', 'hooks'),
46
+ verbose: ctx.flags.verbose,
47
+ globalMode: true,
48
+ cliPath: process.argv[1] || path.join(ctx.packageRoot, 'bin', 'doukui.js'),
49
+ });
50
+
51
+ // Build all plugins (skills + hooks)
52
+ var result = globalBuilder.build();
53
+
54
+ if (result.success) {
55
+ if (ctx.flags.verbose) {
56
+ console.log(ctx.colorize('[doukui] Updating global settings.json...', 'dim'));
57
+ }
58
+ // Register hooks in global settings.json
59
+ globalBuilder.updateSettings(homeDir, ctx.packageRoot);
60
+ }
61
+
62
+ // Apply colors to summary output
63
+ var coloredSummary = result.summary
64
+ .replace(/Build SUCCEEDED/g, ctx.colorize('Build SUCCEEDED', 'green'))
65
+ .replace(/Build COMPLETED WITH ERRORS/g, ctx.colorize('Build COMPLETED WITH ERRORS', 'yellow'))
66
+ .replace(/Validation PASSED/g, ctx.colorize('Validation PASSED', 'green'))
67
+ .replace(/Validation FAILED/g, ctx.colorize('Validation FAILED', 'red'));
68
+
69
+ console.log(coloredSummary);
70
+
71
+ if (result.success) {
72
+ console.log(ctx.colorize('[doukui] Global settings updated: ~/.claude/settings.json', 'green'));
73
+ console.log(ctx.colorize('[doukui] Done! Skills and hooks are globally available.', 'green'));
74
+ console.log('');
75
+ console.log(ctx.colorize('You can now use doukui in any project directory.', 'cyan'));
76
+ console.log(ctx.colorize('Run "doukui init" in your project to get started.', 'dim'));
77
+ }
78
+
79
+ ctx.exit(result.success ? 0 : 1);
80
+ },
81
+ };
@@ -0,0 +1,140 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+
6
+ /**
7
+ * Status command - Show build status and plugin statistics
8
+ * @public
9
+ */
10
+ module.exports = {
11
+ name: 'status',
12
+ description: 'Show build status and plugin statistics',
13
+ /**
14
+ * Execute the status command.
15
+ * @public
16
+ * @param {object} ctx - CLI context object
17
+ */
18
+ execute: function (ctx) {
19
+ console.log(ctx.colorize('=== Doukui Status ===', 'cyan'));
20
+ console.log('');
21
+
22
+ // Package version
23
+ console.log('Version: ' + ctx.colorize(ctx.packageVersion, 'green'));
24
+ console.log('');
25
+
26
+ // Target and package roots
27
+ console.log('Target project root: ' + ctx.targetRoot);
28
+ console.log('Package root: ' + ctx.packageRoot);
29
+ console.log('');
30
+
31
+ // Build status - check if .claude/skills exists
32
+ var skillsDir = ctx.skillsDir;
33
+ var hooksDir = ctx.hooksDir;
34
+ var settingsPath = ctx.settingsPath;
35
+ var configPath = ctx.configPath;
36
+
37
+ console.log(ctx.colorize('Build Status:', 'cyan'));
38
+ var statusLabels = [
39
+ ['.claude/skills/:', skillsDir],
40
+ ['.claude/hooks/:', hooksDir],
41
+ ['settings.json:', settingsPath],
42
+ ['harness-config.yaml:', configPath],
43
+ ];
44
+ var maxLabelLen = 0;
45
+ for (var li = 0; li < statusLabels.length; li++) {
46
+ if (statusLabels[li][0].length > maxLabelLen) maxLabelLen = statusLabels[li][0].length;
47
+ }
48
+ for (var si = 0; si < statusLabels.length; si++) {
49
+ var label = statusLabels[si][0];
50
+ var padding = ' '.repeat(maxLabelLen - label.length + 2);
51
+ var exists = fs.existsSync(statusLabels[si][1]);
52
+ console.log(' ' + label + padding + (exists ? ctx.colorize('exists', 'green') : ctx.colorize('missing', 'red')));
53
+ }
54
+ console.log('');
55
+
56
+ // Plugin statistics
57
+ var builder = ctx.createBuilder();
58
+ var registry = builder._readRegistry();
59
+ var plugins = registry.plugins || [];
60
+
61
+ var stats = {
62
+ total: plugins.length,
63
+ enabled: 0,
64
+ disabled: 0,
65
+ skill: 0,
66
+ hook: 0,
67
+ validator: 0,
68
+ provider: 0,
69
+ };
70
+
71
+ var pluginTypes = {};
72
+ var pluginNames = [];
73
+
74
+ for (var i = 0; i < plugins.length; i++) {
75
+ var p = plugins[i];
76
+ if (p.enabled !== false) {
77
+ stats.enabled++;
78
+ pluginNames.push(p.name);
79
+ } else {
80
+ stats.disabled++;
81
+ continue;
82
+ }
83
+
84
+ // Read plugin type from plugin.json (enabled only)
85
+ var pluginDir = path.join(ctx.packageRoot, 'plugins', 'core', p.source || p.name);
86
+ var metaPath = path.join(pluginDir, 'plugin.json');
87
+ if (fs.existsSync(metaPath)) {
88
+ try {
89
+ var meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8'));
90
+ var type = meta.type || 'unknown';
91
+ pluginTypes[p.name] = type;
92
+ if (stats.hasOwnProperty(type)) {
93
+ stats[type]++;
94
+ }
95
+ } catch (e) {
96
+ // skip parse errors
97
+ }
98
+ }
99
+ }
100
+
101
+ console.log(ctx.colorize('Plugin Statistics:', 'cyan'));
102
+ console.log(' Total plugins: ' + stats.total);
103
+ console.log(' Enabled plugins: ' + ctx.colorize(stats.enabled, 'green'));
104
+ console.log(' Disabled plugins: ' + (stats.disabled > 0 ? ctx.colorize(String(stats.disabled), 'yellow') : '0'));
105
+ console.log('');
106
+ console.log(' By type:');
107
+ console.log(' Skills: ' + stats.skill);
108
+ console.log(' Hooks: ' + stats.hook);
109
+ console.log(' Validators: ' + stats.validator);
110
+ console.log(' Providers: ' + stats.provider);
111
+ console.log('');
112
+
113
+ // Show last build time if available (scan files inside skill subdirs)
114
+ if (fs.existsSync(skillsDir)) {
115
+ var latestTime = null;
116
+ try {
117
+ var entries = fs.readdirSync(skillsDir);
118
+ for (var ei = 0; ei < entries.length; ei++) {
119
+ var skillEntryDir = path.join(skillsDir, entries[ei]);
120
+ try {
121
+ var skillFiles = fs.readdirSync(skillEntryDir);
122
+ for (var fi = 0; fi < skillFiles.length; fi++) {
123
+ try {
124
+ var fileStat = fs.statSync(path.join(skillEntryDir, skillFiles[fi]));
125
+ if (!latestTime || fileStat.mtime > latestTime) {
126
+ latestTime = fileStat.mtime;
127
+ }
128
+ } catch (ignore) {}
129
+ }
130
+ } catch (ignore) {}
131
+ }
132
+ } catch (ignore) {}
133
+ if (latestTime) {
134
+ console.log('Last build: ' + latestTime.toLocaleString());
135
+ }
136
+ }
137
+
138
+ ctx.exit(0);
139
+ },
140
+ };
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ var cleanup = require('../../plugins/runtime/team-cleanup');
4
+ var TeamCleanupError = cleanup.TeamCleanupError;
5
+
6
+ /**
7
+ * team-cleanup command - Deterministically remove an agent team's
8
+ * teams/ and tasks/ directories (cross-platform + safety-checked).
9
+ *
10
+ * Usage:
11
+ * node bin/doukui.js team-cleanup <team_name> [--dry-run] [--force]
12
+ *
13
+ * Advantages over the old `rm -rf $HOME/...` pseudo-code:
14
+ * - Cross-platform fs.rmSync (no shell-quoting hazards, works on Windows)
15
+ * - Bypasses the harness Bash permission system (no settings.json entry)
16
+ * - Validates team name charset + path-traversal guards before any write
17
+ *
18
+ * @public
19
+ */
20
+ module.exports = {
21
+ name: 'team-cleanup',
22
+ description: '确定性地移除 agent team 的 teams/ 和 tasks/ 目录(跨平台 + 安全校验)',
23
+ aliases: ['team-cleanup'],
24
+ /**
25
+ * Execute the team-cleanup command.
26
+ *
27
+ * Parses process.argv directly (ctx.flags does not expose positional
28
+ * args), separating the first positional team_name from --dry-run / --force.
29
+ *
30
+ * @public
31
+ * @param {object} ctx - CLI context object
32
+ */
33
+ execute: function (ctx) {
34
+ var rawArgs = process.argv.slice(2);
35
+ var teamName = null;
36
+ var dryRun = false;
37
+ var force = false;
38
+
39
+ // ctx.command is the command name already resolved by bin/doukui.js
40
+ // (e.g. 'team-cleanup'). Skip the first occurrence of it so the command
41
+ // name itself isn't mistaken for the team_name positional argument.
42
+ var commandName = ctx.command || 'team-cleanup';
43
+ var commandSkipped = false;
44
+
45
+ for (var i = 0; i < rawArgs.length; i++) {
46
+ var arg = rawArgs[i];
47
+ if (arg === '--dry-run') {
48
+ dryRun = true;
49
+ } else if (arg === '--force') {
50
+ force = true;
51
+ } else if (arg.indexOf('--') === 0) {
52
+ // Skip other global flags (--root, --no-color, --verbose, ...) already
53
+ // consumed by bin/doukui.js. Their values, when present, also start
54
+ // with non-dash so we'd capture them as teamName below unless skipped.
55
+ // If --root took a value, that value is already removed from argv by
56
+ // doukui.js's index bumping, so no extra handling is needed here.
57
+ continue;
58
+ } else if (!commandSkipped && arg === commandName) {
59
+ // First positional matching the command name is the command itself.
60
+ commandSkipped = true;
61
+ } else if (teamName === null) {
62
+ teamName = arg;
63
+ }
64
+ // Additional positional args beyond the team name are ignored.
65
+ }
66
+
67
+ console.log(ctx.colorize('[doukui] team-cleanup', 'cyan'));
68
+ console.log('');
69
+
70
+ // 1. Validate input.
71
+ var validation = cleanup.validateTeamName(teamName);
72
+ if (!validation.ok) {
73
+ var reasonText = validation.reason || 'invalid';
74
+ console.error(ctx.colorize('Error: invalid team name "' + (teamName === null ? '' : teamName) + '" (' + reasonText + ')', 'red'));
75
+ console.error('Team names must match /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/ and must not contain path separators.');
76
+ console.error('');
77
+ console.error('Usage: node bin/doukui.js team-cleanup <team_name> [--dry-run] [--force]');
78
+ ctx.exit(1);
79
+ return;
80
+ }
81
+
82
+ console.log('Team: ' + ctx.colorize(teamName, 'green'));
83
+ if (dryRun) console.log('Mode: ' + ctx.colorize('dry-run (no changes)', 'yellow'));
84
+ if (force) console.log('Force: ' + ctx.colorize('yes (fresh-active guard skipped)', 'yellow'));
85
+ console.log('');
86
+
87
+ // 2. Run cleanup. Production CLI does not pass teamDeleteFn.
88
+ var result;
89
+ try {
90
+ result = cleanup.cleanupTeam(teamName, {
91
+ dryRun: dryRun,
92
+ force: force,
93
+ log: function (msg) {
94
+ console.log(' ' + ctx.colorize(msg, 'dim'));
95
+ },
96
+ });
97
+ } catch (e) {
98
+ if (e instanceof TeamCleanupError || (e && e.name === 'TeamCleanupError')) {
99
+ console.error(ctx.colorize('Error: ' + e.message + ' [code: ' + e.code + ']', 'red'));
100
+ ctx.exit(1);
101
+ return;
102
+ }
103
+ throw e;
104
+ }
105
+
106
+ // 3. Print stylized result.
107
+ if (result.skipped) {
108
+ console.log(ctx.colorize('No team artifacts found — nothing to clean.', 'dim'));
109
+ ctx.exit(0);
110
+ return;
111
+ }
112
+
113
+ if (dryRun && result.wouldDelete && result.wouldDelete.length > 0) {
114
+ console.log(ctx.colorize('Dry run — would delete:', 'cyan'));
115
+ for (var w = 0; w < result.wouldDelete.length; w++) {
116
+ console.log(' - ' + result.wouldDelete[w]);
117
+ }
118
+ ctx.exit(0);
119
+ return;
120
+ }
121
+
122
+ // Fresh-active-team guard refused (non-force run).
123
+ var guardError = findErrorKind(result.errors, 'fresh_active_team');
124
+ if (guardError) {
125
+ console.warn(ctx.colorize('Refused: ' + guardError.message, 'yellow'));
126
+ console.warn('Pass --force to override.');
127
+ ctx.exit(1);
128
+ return;
129
+ }
130
+
131
+ var total = result.teamsDeleted + result.tasksDeleted;
132
+ var attempted = (result.teamsDeleted + result.tasksDeleted + result.errors.length);
133
+ if (attempted > 0 && result.errors.length === 0) {
134
+ // Full success.
135
+ console.log(ctx.colorize('Deleted ' + total + ' path(s) for team "' + teamName + '".', 'green'));
136
+ ctx.exit(0);
137
+ return;
138
+ }
139
+
140
+ if (result.errors.length > 0 && total > 0) {
141
+ // Partial success.
142
+ console.warn(ctx.colorize('Partially cleaned: ' + total + ' path(s) deleted, ' + result.errors.length + ' error(s).', 'yellow'));
143
+ printErrors(ctx, result.errors);
144
+ ctx.exit(0);
145
+ return;
146
+ }
147
+
148
+ // All attempts failed.
149
+ if (result.errors.length > 0) {
150
+ console.error(ctx.colorize('Failed to clean team "' + teamName + '": ' + result.errors.length + ' error(s).', 'red'));
151
+ printErrors(ctx, result.errors);
152
+ ctx.exit(1);
153
+ return;
154
+ }
155
+
156
+ // Defensive: no deletion, no error, not skipped/dry-run (shouldn't happen).
157
+ console.warn(ctx.colorize('Completed with no changes.', 'yellow'));
158
+ ctx.exit(0);
159
+ },
160
+ };
161
+
162
+ /**
163
+ * Find the first error descriptor matching a kind. Internal helper.
164
+ *
165
+ * @private
166
+ * @param {Array} errors - result.errors[]
167
+ * @param {string} kind
168
+ * @returns {object|null}
169
+ */
170
+ function findErrorKind(errors, kind) {
171
+ if (!errors) return null;
172
+ for (var i = 0; i < errors.length; i++) {
173
+ if (errors[i] && errors[i].kind === kind) return errors[i];
174
+ }
175
+ return null;
176
+ }
177
+
178
+ /**
179
+ * Print each error descriptor on its own red line. Internal helper.
180
+ *
181
+ * @private
182
+ * @param {object} ctx
183
+ * @param {Array} errors
184
+ */
185
+ function printErrors(ctx, errors) {
186
+ for (var i = 0; i < errors.length; i++) {
187
+ var e = errors[i];
188
+ console.error(' ' + ctx.colorize('[' + (e.kind || 'error') + '] ' + e.path + ': ' + e.message, 'red'));
189
+ }
190
+ }
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Validate-config command - Validate harness-config.yaml
5
+ * @public
6
+ */
7
+ module.exports = {
8
+ name: 'validate-config',
9
+ description: 'Validate harness-config.yaml',
10
+ /**
11
+ * Execute the validate-config command.
12
+ * @public
13
+ * @param {object} ctx - CLI context object
14
+ */
15
+ execute: function (ctx) {
16
+ var builder = ctx.createBuilder();
17
+ var result = builder.validateConfig();
18
+ console.log(result.summary);
19
+ if (!result.valid) {
20
+ console.log('');
21
+ console.log('Errors:');
22
+ for (var i = 0; i < result.errors.length; i++) {
23
+ console.log(' - ' + result.errors[i]);
24
+ }
25
+ }
26
+ if (result.warnings.length > 0) {
27
+ console.log('');
28
+ console.log('Warnings:');
29
+ for (var j = 0; j < result.warnings.length; j++) {
30
+ console.log(' - ' + result.warnings[j]);
31
+ }
32
+ }
33
+ ctx.exit(result.valid ? 0 : 1);
34
+ },
35
+ };
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Validate command - Validate plugin.json files without building
5
+ * @public
6
+ */
7
+ module.exports = {
8
+ name: 'validate',
9
+ description: 'Validate plugin.json files',
10
+ /**
11
+ * Execute the validate command.
12
+ * @public
13
+ * @param {object} ctx - CLI context object
14
+ */
15
+ execute: function (ctx) {
16
+ var builder = ctx.createBuilder();
17
+ var result = builder.validate();
18
+ console.log(result.summary);
19
+ ctx.exit(result.valid ? 0 : 1);
20
+ },
21
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Version command - Show version information
5
+ * @public
6
+ */
7
+ module.exports = {
8
+ name: 'version',
9
+ description: 'Show version information',
10
+ /**
11
+ * Execute the version command.
12
+ * @public
13
+ * @param {object} ctx - CLI context object
14
+ */
15
+ execute: function (ctx) {
16
+ console.log('doukui v' + ctx.packageVersion);
17
+ console.log('');
18
+ console.log('Node.js version: ' + process.version);
19
+ console.log('Package root: ' + ctx.packageRoot);
20
+ ctx.exit(0);
21
+ },
22
+ };