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,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;
|