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.
Files changed (135) 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 +1398 -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 +1397 -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 +572 -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 +390 -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-reader.js +763 -0
  118. package/plugins/runtime/plugin-loader.js +798 -0
  119. package/plugins/runtime/plugin-trust.js +182 -0
  120. package/plugins/runtime/plugin-validator.js +491 -0
  121. package/plugins/runtime/provider-failover.js +114 -0
  122. package/plugins/runtime/provider-resolver.js +342 -0
  123. package/plugins/runtime/reflection-evaluator.js +540 -0
  124. package/plugins/runtime/resolve-plugin-path.js +297 -0
  125. package/plugins/runtime/safe-path.js +119 -0
  126. package/plugins/runtime/sandbox-context.js +235 -0
  127. package/plugins/runtime/sandbox-manager.js +609 -0
  128. package/plugins/runtime/sandbox-worker.js +215 -0
  129. package/plugins/runtime/settings-merger.js +172 -0
  130. package/plugins/runtime/state-store.js +527 -0
  131. package/plugins/runtime/team-cleanup.js +497 -0
  132. package/plugins/runtime/text-tokenize.js +25 -0
  133. package/plugins/runtime/validator-pipeline.js +475 -0
  134. package/plugins/runtime/yaml-parser.js +692 -0
  135. package/templates/harness-config.yaml +388 -0
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Hook: Session Start
3
+ *
4
+ * SessionStart hook that injects doukui rules into Claude Code's
5
+ * system-reminder context via hookSpecificOutput.additionalContext.
6
+ *
7
+ * This ensures plan-mode rules appear at the same priority level as
8
+ * superpowers skills, rather than relying on CLAUDE.md static files.
9
+ *
10
+ * Usage (CLI):
11
+ * node plugins/core/hook-session-start/index.js
12
+ *
13
+ * Output: JSON with hookSpecificOutput.additionalContext containing
14
+ * plan-mode priority rules for task-creation skills.
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ var fs = require('fs');
20
+ var path = require('path');
21
+
22
+ /**
23
+ * Resolve the package root directory from __dirname.
24
+ * Walks up from the hook's location to find the doukui package root.
25
+ * Used to locate plugin-registry.json regardless of installation mode.
26
+ *
27
+ * For global installs, resolves to the global npm package directory.
28
+ * For local installs, resolves to the project's node_modules/doukui.
29
+ *
30
+ * @returns {string}
31
+ */
32
+ function resolvePackageRoot() {
33
+ // This hook is at: plugins/core/hook-session-start/index.js
34
+ // Package root is three levels up from __dirname
35
+ var dir = path.resolve(__dirname, '../../..');
36
+
37
+ // Verify we're at the right location (should contain plugins/ directory)
38
+ for (var i = 0; i < 5; i++) {
39
+ if (fs.existsSync(path.join(dir, 'plugins'))) return dir;
40
+ if (fs.existsSync(path.join(dir, 'package.json'))) return dir;
41
+ var parent = path.dirname(dir);
42
+ if (parent === dir) break;
43
+ dir = parent;
44
+ }
45
+
46
+ // Fallback: try to find global doukui in node_modules
47
+ // Check common global npm directories
48
+ var globalPaths = [
49
+ path.join(process.env.APPDATA || '', 'npm', 'node_modules', 'doukui'),
50
+ path.join(process.env.npm_config_prefix || '/usr/local', 'lib', 'node_modules', 'doukui'),
51
+ ];
52
+
53
+ for (var j = 0; j < globalPaths.length; j++) {
54
+ if (fs.existsSync(path.join(globalPaths[j], 'plugins'))) {
55
+ return globalPaths[j];
56
+ }
57
+ }
58
+
59
+ // Fallback to computed path
60
+ return path.resolve(__dirname, '../../..');
61
+ }
62
+
63
+ /**
64
+ * Walk up from a directory to find the project root (contains .claude/ or plugins/).
65
+ * Always uses process.cwd() for CWD-based project resolution.
66
+ * @param {string} [startDir]
67
+ * @returns {string}
68
+ */
69
+ function resolveProjectRoot(startDir) {
70
+ // Always use process.cwd() to find the actual project root
71
+ // This allows hooks to work correctly regardless of installation mode
72
+ var dir = startDir || process.cwd();
73
+ for (var i = 0; i < 10; i++) {
74
+ if (fs.existsSync(path.join(dir, '.claude'))) return dir;
75
+ if (fs.existsSync(path.join(dir, 'task.md'))) return dir;
76
+ if (fs.existsSync(path.join(dir, 'CLAUDE.md'))) return dir;
77
+ var parent = path.dirname(dir);
78
+ if (parent === dir) break;
79
+ dir = parent;
80
+ }
81
+ return process.cwd();
82
+ }
83
+
84
+ /**
85
+ * Read plugin-registry.json and find skills with plan_mode_required.
86
+ * @param {string} packageRoot - the doukui package root directory
87
+ * @returns {string[]} skill names
88
+ */
89
+ function findPlanModeSkills(packageRoot) {
90
+ var registryPath = path.join(packageRoot, 'plugins', 'plugin-registry.json');
91
+ var planModeSkills = [];
92
+
93
+ try {
94
+ var content = fs.readFileSync(registryPath, 'utf-8');
95
+ var registry = JSON.parse(content);
96
+ var plugins = registry.plugins || [];
97
+
98
+ for (var i = 0; i < plugins.length; i++) {
99
+ var entry = plugins[i];
100
+ if (!entry.source) continue;
101
+
102
+ var pluginDir = path.join(packageRoot, 'plugins', 'core', entry.source);
103
+ var pluginJsonPath = path.join(pluginDir, 'plugin.json');
104
+
105
+ try {
106
+ var meta = JSON.parse(fs.readFileSync(pluginJsonPath, 'utf-8'));
107
+ if (meta.type !== 'skill') continue;
108
+
109
+ var hasPlanMode = false;
110
+
111
+ // Check plugin.json config
112
+ if (meta.config && meta.config.plan_mode_required) {
113
+ hasPlanMode = true;
114
+ }
115
+
116
+ // Fallback: check skill.md front-matter
117
+ if (!hasPlanMode) {
118
+ var skillMdPath = path.join(pluginDir, 'skill.md');
119
+ if (fs.existsSync(skillMdPath)) {
120
+ var skillContent = fs.readFileSync(skillMdPath, 'utf-8');
121
+ if (/^---[\s\S]*?plan_mode_required:\s*true[\s\S]*?---/.test(skillContent)) {
122
+ hasPlanMode = true;
123
+ }
124
+ }
125
+ }
126
+
127
+ if (hasPlanMode) {
128
+ planModeSkills.push(meta.name || entry.name);
129
+ }
130
+ } catch (e) {
131
+ // skip unparseable
132
+ }
133
+ }
134
+ } catch (e) {
135
+ // registry may not exist
136
+ }
137
+
138
+ return planModeSkills;
139
+ }
140
+
141
+ /**
142
+ * Build the additionalContext string for SessionStart hook output.
143
+ * @param {string} packageRoot - the doukui package root directory
144
+ * @returns {string}
145
+ */
146
+ function buildContext(packageRoot) {
147
+ var planModeSkills = findPlanModeSkills(packageRoot);
148
+
149
+ if (planModeSkills.length === 0) return '';
150
+
151
+ var lines = [];
152
+ lines.push('Doukui Plan Mode 规则已激活。');
153
+ lines.push('');
154
+ lines.push('当以下 skill 被触发时,必须直接调用 EnterPlanMode 进入 Plan 模式,不得先执行 brainstorming 或其他分析工作:');
155
+
156
+ for (var i = 0; i < planModeSkills.length; i++) {
157
+ lines.push('- ' + planModeSkills[i]);
158
+ }
159
+
160
+ lines.push('');
161
+ lines.push('这些 skill 已标注 plan_mode_required: true,优先级高于 superpowers:brainstorming。收到匹配请求时,跳过 brainstorming 检查,立即进入 Plan 模式。');
162
+
163
+ return lines.join('\n');
164
+ }
165
+
166
+ /**
167
+ * Escape a string for safe embedding in a JSON string value.
168
+ * @param {string} s
169
+ * @returns {string}
170
+ */
171
+ function escapeForJson(s) {
172
+ return s
173
+ .replace(/\\/g, '\\\\')
174
+ .replace(/"/g, '\\"')
175
+ .replace(/\n/g, '\\n')
176
+ .replace(/\r/g, '\\r')
177
+ .replace(/\t/g, '\\t');
178
+ }
179
+
180
+ /**
181
+ * Check if this hook execution should be skipped to prevent double-triggering.
182
+ *
183
+ * Double-triggering can occur when:
184
+ * 1. A hook is registered globally (via global npm install)
185
+ * 2. The same hook is also registered at project level (via local build)
186
+ *
187
+ * We detect this by checking whether a marker file exists with a recent timestamp.
188
+ *
189
+ * @param {string} projectRoot - the project root directory
190
+ * @returns {boolean} true if this execution should be skipped
191
+ */
192
+ function shouldSkipForDoubleTrigger(projectRoot) {
193
+ var markerPath = path.join(projectRoot, '.claude', '.hook-session-start-marker');
194
+
195
+ // If another hook process is marked as active, skip
196
+ if (fs.existsSync(markerPath)) {
197
+ try {
198
+ var marker = fs.readFileSync(markerPath, 'utf-8');
199
+ var markerData = JSON.parse(marker);
200
+
201
+ // If marker is recent (< 5 seconds), skip to prevent double execution
202
+ var now = Date.now();
203
+ if (markerData.timestamp && (now - markerData.timestamp) < 5000) {
204
+ return true;
205
+ }
206
+ // Stale marker — clean it up
207
+ try { fs.unlinkSync(markerPath); } catch (e) { /* ignore */ }
208
+ } catch (e) {
209
+ // Invalid marker, clean up
210
+ try { fs.unlinkSync(markerPath); } catch (e2) { /* ignore */ }
211
+ }
212
+ }
213
+
214
+ // Mark this hook as active
215
+ try {
216
+ fs.writeFileSync(
217
+ markerPath,
218
+ JSON.stringify({ timestamp: Date.now(), pid: process.pid }),
219
+ 'utf-8'
220
+ );
221
+ } catch (e) {
222
+ // Failed to write marker, continue anyway
223
+ }
224
+
225
+ return false;
226
+ }
227
+
228
+ // --- Main ---
229
+ (function main() {
230
+ // Only run main if executed directly (not required as a module)
231
+ if (require.main === module) {
232
+ var packageRoot = resolvePackageRoot();
233
+ var projectRoot = resolveProjectRoot();
234
+
235
+ // Check for double-triggering prevention
236
+ if (shouldSkipForDoubleTrigger(projectRoot)) {
237
+ // Skip execution to prevent double-triggering, output empty result
238
+ process.stdout.write('{}\n');
239
+ process.exit(0);
240
+ }
241
+
242
+ var context = buildContext(packageRoot);
243
+
244
+ if (!context) {
245
+ // No plan-mode skills found, output empty context
246
+ process.stdout.write('{}\n');
247
+ process.exit(0);
248
+ }
249
+
250
+ var escaped = escapeForJson(context);
251
+
252
+ // Claude Code SessionStart hook output format
253
+ var output = '{\n "hookSpecificOutput": {\n "hookEventName": "SessionStart",\n "additionalContext": "' + escaped + '"\n }\n}\n';
254
+
255
+ process.stdout.write(output);
256
+ process.exit(0);
257
+ }
258
+ })();
259
+
260
+ // Export a no-op class for PluginLoader compatibility
261
+ class SessionStartHook {
262
+ constructor() {
263
+ this.name = 'hook-session-start';
264
+ this.version = '1.0.0';
265
+ this.description = 'SessionStart hook for plan-mode rules';
266
+ this.type = 'hook';
267
+ }
268
+
269
+ async onActivate(context) {
270
+ // No-op - this hook is CLI-only
271
+ }
272
+
273
+ async handle(context) {
274
+ return { allowed: true };
275
+ }
276
+ }
277
+
278
+ module.exports = SessionStartHook;
279
+
280
+ // Exposed for unit testing (plan_mode_required detection contract, WP-176).
281
+ module.exports.findPlanModeSkills = findPlanModeSkills;
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "hook-session-start",
3
+ "version": "1.0.0",
4
+ "type": "hook",
5
+ "description": "SessionStart hook - 注入 plan-mode 优先级规则到 system-reminder,确保任务创建类 skill 强制进入 Plan 模式",
6
+ "provides": ["hook:session-start"]
7
+ }