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,376 @@
1
+ /**
2
+ * Provider: Role Registry
3
+ *
4
+ * Wraps role-registry.yaml and individual role YAML files to provide
5
+ * role matching, querying, and listing capabilities.
6
+ * Implements the ProviderPlugin interface from plugin-interface.js.
7
+ *
8
+ * Capabilities:
9
+ * - match(query) match roles by keyword, alias, or tag
10
+ * - getAll() return all loaded roles
11
+ * - getById(roleId) return a specific role by its id
12
+ * - getByAlias(alias) lookup role by Chinese alias
13
+ * - getAliases() return the full alias mapping
14
+ * - getCategories() return role category definitions
15
+ */
16
+
17
+ 'use strict';
18
+
19
+ var path = require('path');
20
+ var fs = require('fs');
21
+ var { ProviderPlugin } = require('../../contracts/plugin-interface');
22
+
23
+ /**
24
+ * Minimal YAML parser — S8/A3 consolidated.
25
+ *
26
+ * Delegates to the shared `yaml-parser.parseSimpleYaml`. Previously this
27
+ * module had its own divergent copy (with a buggy list-of-objects branch and
28
+ * no size/depth guards). The shared parser also fixes B4 (top-level scalar
29
+ * arrays now parse correctly, which matters because role files use lists for
30
+ * expertise/keywords/task_types).
31
+ * @param {string} content
32
+ * @returns {object}
33
+ */
34
+ function parseSimpleYaml(content) {
35
+ var sharedParser = require('../../runtime/yaml-parser');
36
+ try {
37
+ return sharedParser.parseSimpleYaml(content);
38
+ } catch (_e) {
39
+ // Oversize / over-depth → empty config (preserve non-throwing behavior)
40
+ return {};
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Parse a role definition YAML file.
46
+ * Extracts structured role data from a role file like coordinator.yaml.
47
+ */
48
+ function parseRoleYaml(content) {
49
+ var data = parseSimpleYaml(content);
50
+
51
+ // Handle multi-line description (pipe | syntax) - already stripped by our parser
52
+ // Just return the parsed structure
53
+ return {
54
+ id: data.id || '',
55
+ name: data.name || '',
56
+ version: data.version || '1.0.0',
57
+ tier: data.tier || '',
58
+ description: data.description || '',
59
+ expertise: Array.isArray(data.expertise) ? data.expertise : [],
60
+ keywords: Array.isArray(data.keywords) ? data.keywords : [],
61
+ task_types: Array.isArray(data.task_types) ? data.task_types : [],
62
+ module_tags: Array.isArray(data.module_tags) ? data.module_tags : [],
63
+ tools: Array.isArray(data.tools) ? data.tools : [],
64
+ subagent_type: data.subagent_type || 'general-purpose',
65
+ model: data.model || '', // WP-D2:模型分级路由(透传给 agent-def-generator 渲染 frontmatter)
66
+ abstract: data.abstract || false,
67
+ memory_file: data.memory_file || '',
68
+ experience_tags: Array.isArray(data.experience_tags) ? data.experience_tags : [],
69
+ prompt_template: data.prompt_template || '',
70
+ };
71
+ }
72
+
73
+
74
+ /**
75
+ * RoleRegistryProvider - provides role matching and querying
76
+ */
77
+ class RoleRegistryProvider extends ProviderPlugin {
78
+ constructor() {
79
+ super();
80
+ this.name = 'provider-role-registry';
81
+ this.version = '1.0.0';
82
+ this.description = 'Role Registry Provider';
83
+ this.provides = 'provider:role-registry';
84
+ this.dependencies = {};
85
+
86
+ /** @type {object|null} parsed registry data */
87
+ this._registry = null;
88
+ /** @type {Map<string, object>} loaded role definitions by id */
89
+ this._roles = new Map();
90
+ /** @type {object} alias mapping */
91
+ this._aliases = {};
92
+ /** @type {string} project root */
93
+ this._projectRoot = '';
94
+ }
95
+
96
+ /**
97
+ * Activate - load and parse the registry and role files.
98
+ * @param {PluginContext} context
99
+ */
100
+ async onActivate(context) {
101
+ this._projectRoot = this._resolveProjectRoot();
102
+ var registryPath = path.join(this._projectRoot, '.claude', 'agents', 'role-registry.yaml');
103
+ this._loadRegistry(registryPath);
104
+ this._loadRoleFiles();
105
+ }
106
+
107
+ /**
108
+ * Factory - return the provider API.
109
+ * @param {PluginContext} context
110
+ * @returns {Promise<object>}
111
+ */
112
+ async factory(context) {
113
+ var self = this;
114
+
115
+ return {
116
+ /**
117
+ * Match roles by keyword, alias, tag, or expertise.
118
+ * @param {string} query - search term
119
+ * @returns {{ id: string, name: string, score: number }[]}
120
+ */
121
+ match: function (query) {
122
+ return self._match(query);
123
+ },
124
+
125
+ /**
126
+ * Get all loaded roles.
127
+ * @returns {object[]}
128
+ */
129
+ getAll: function () {
130
+ return Array.from(self._roles.values());
131
+ },
132
+
133
+ /**
134
+ * Get a role by its ID.
135
+ * @param {string} roleId
136
+ * @returns {object|undefined}
137
+ */
138
+ getById: function (roleId) {
139
+ return self._roles.get(roleId);
140
+ },
141
+
142
+ /**
143
+ * Get a role by its Chinese alias.
144
+ * @param {string} alias
145
+ * @returns {object|undefined}
146
+ */
147
+ getByAlias: function (alias) {
148
+ var roleId = self._aliases[alias];
149
+ if (!roleId) return undefined;
150
+ return self._roles.get(roleId);
151
+ },
152
+
153
+ /**
154
+ * Get the full alias mapping.
155
+ * @returns {object}
156
+ */
157
+ getAliases: function () {
158
+ return Object.assign({}, self._aliases);
159
+ },
160
+
161
+ /**
162
+ * Get category definitions from the registry.
163
+ * @returns {object}
164
+ */
165
+ getCategories: function () {
166
+ if (!self._registry || !self._registry.categories) return {};
167
+ return self._registry.categories;
168
+ },
169
+
170
+ /**
171
+ * Get the default fallback role ID.
172
+ * @returns {string}
173
+ */
174
+ getDefaultRole: function () {
175
+ return (self._registry && self._registry.default_role) || 'implementer';
176
+ },
177
+
178
+ /**
179
+ * Get tag-to-role mappings.
180
+ * @returns {object}
181
+ */
182
+ getTagMappings: function () {
183
+ if (!self._registry || !self._registry.tag_to_role) return {};
184
+ return self._registry.tag_to_role;
185
+ },
186
+ };
187
+ }
188
+
189
+ /**
190
+ * Match roles by query string.
191
+ * Scores each role based on keyword, expertise, alias, and tag matches.
192
+ * @param {string} query
193
+ * @returns {{ id: string, name: string, score: number }[]}
194
+ */
195
+ _match(query) {
196
+ if (!query) return [];
197
+ var self = this;
198
+ var q = query.toLowerCase();
199
+ var scores = new Map();
200
+ var weights = (this._registry && this._registry.matching_weights) || {
201
+ keyword: 0.5,
202
+ task_type: 0.3,
203
+ module_tag: 0.2,
204
+ inheritance_factor: 0.5,
205
+ };
206
+
207
+ // Check aliases (exact match)
208
+ var aliasRoleIds = [];
209
+ for (var alias in this._aliases) {
210
+ if (alias.toLowerCase().indexOf(q) !== -1) {
211
+ aliasRoleIds.push(this._aliases[alias]);
212
+ }
213
+ }
214
+
215
+ // Check tag_to_role
216
+ var tagMappings = (this._registry && this._registry.tag_to_role) || {};
217
+ for (var tag in tagMappings) {
218
+ var tagClean = tag.replace(/[\[\]]/g, '').toLowerCase();
219
+ if (tagClean.indexOf(q) !== -1 || q.indexOf(tagClean) !== -1) {
220
+ var roleIds = tagMappings[tag];
221
+ if (Array.isArray(roleIds)) {
222
+ for (var t = 0; t < roleIds.length; t++) {
223
+ var rid = roleIds[t];
224
+ var prev = scores.get(rid) || 0;
225
+ scores.set(rid, prev + 0.4);
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ // Score each role by keywords, expertise, and task_types
232
+ this._roles.forEach(function (role, id) {
233
+ var score = 0;
234
+
235
+ // Keyword match
236
+ if (role.keywords) {
237
+ for (var k = 0; k < role.keywords.length; k++) {
238
+ if (role.keywords[k].toLowerCase().indexOf(q) !== -1) {
239
+ score += weights.keyword;
240
+ break;
241
+ }
242
+ }
243
+ }
244
+
245
+ // Expertise match
246
+ if (role.expertise) {
247
+ for (var e = 0; e < role.expertise.length; e++) {
248
+ if (role.expertise[e].toLowerCase().indexOf(q) !== -1) {
249
+ score += 0.3;
250
+ break;
251
+ }
252
+ }
253
+ }
254
+
255
+ // Task type match
256
+ if (role.task_types) {
257
+ for (var tt = 0; tt < role.task_types.length; tt++) {
258
+ if (role.task_types[tt].toLowerCase().indexOf(q) !== -1) {
259
+ score += weights.task_type;
260
+ break;
261
+ }
262
+ }
263
+ }
264
+
265
+ // Module tag match
266
+ if (role.module_tags) {
267
+ for (var mt = 0; mt < role.module_tags.length; mt++) {
268
+ if (role.module_tags[mt].toLowerCase().indexOf(q) !== -1) {
269
+ score += weights.module_tag;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+
275
+ // Name match
276
+ if (role.name && role.name.toLowerCase().indexOf(q) !== -1) {
277
+ score += 0.4;
278
+ }
279
+
280
+ // ID match
281
+ if (id.toLowerCase().indexOf(q) !== -1) {
282
+ score += 0.3;
283
+ }
284
+
285
+ // Boost for alias matches
286
+ if (aliasRoleIds.indexOf(id) !== -1) {
287
+ score += 0.5;
288
+ }
289
+
290
+ if (score > 0) {
291
+ scores.set(id, (scores.get(id) || 0) + score);
292
+ }
293
+ });
294
+
295
+ // Convert scores to sorted results
296
+ var results = [];
297
+ scores.forEach(function (score, id) {
298
+ var role = self._roles.get(id);
299
+ results.push({
300
+ id: id,
301
+ name: role ? role.name : id,
302
+ score: Math.round(score * 100) / 100,
303
+ });
304
+ });
305
+
306
+ results.sort(function (a, b) { return b.score - a.score; });
307
+ return results;
308
+ }
309
+
310
+ /**
311
+ * Load and parse the role registry YAML.
312
+ * @param {string} filePath
313
+ */
314
+ _loadRegistry(filePath) {
315
+ try {
316
+ var content = fs.readFileSync(filePath, 'utf-8');
317
+ this._registry = parseSimpleYaml(content);
318
+ this._aliases = this._registry.aliases || {};
319
+ } catch (err) {
320
+ this._registry = { categories: {}, aliases: {}, default_role: 'implementer' };
321
+ this._aliases = {};
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Load all role files referenced in the registry.
327
+ */
328
+ _loadRoleFiles() {
329
+ var roleFiles = (this._registry && this._registry.role_files) || [];
330
+ var agentsDir = path.join(this._projectRoot, '.claude', 'agents');
331
+
332
+ for (var i = 0; i < roleFiles.length; i++) {
333
+ var entry = roleFiles[i];
334
+ // entry can be a string "path: ..." or an object { path: "..." }
335
+ var relPath = '';
336
+ if (typeof entry === 'string') {
337
+ // parse "path: value"
338
+ var match = entry.match(/path:\s*(.+)/);
339
+ relPath = match ? match[1].trim() : entry;
340
+ } else if (entry && entry.path) {
341
+ relPath = entry.path;
342
+ }
343
+ if (!relPath) continue;
344
+
345
+ var fullPath = path.join(agentsDir, relPath);
346
+ try {
347
+ var content = fs.readFileSync(fullPath, 'utf-8');
348
+ var roleData = parseRoleYaml(content);
349
+ if (roleData.id) {
350
+ this._roles.set(roleData.id, roleData);
351
+ }
352
+ } catch (err) {
353
+ // Skip unreadable role files silently
354
+ }
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Resolve the project root directory.
360
+ * @returns {string}
361
+ */
362
+ _resolveProjectRoot() {
363
+ var dir = process.cwd();
364
+ for (var i = 0; i < 10; i++) {
365
+ if (fs.existsSync(path.join(dir, 'task.md'))) return dir;
366
+ if (fs.existsSync(path.join(dir, '.claude'))) return dir;
367
+ var parent = path.dirname(dir);
368
+ if (parent === dir) break;
369
+ dir = parent;
370
+ }
371
+ return process.cwd();
372
+ }
373
+ }
374
+
375
+ module.exports = RoleRegistryProvider;
376
+ module.exports._parseRoleYaml = parseRoleYaml; // WP-D2:agent-def-generator 复用同一解析器
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "provider-role-registry",
3
+ "version": "1.0.0",
4
+ "type": "provider",
5
+ "description": "角色注册表 Provider - 包装 role-registry.yaml 和角色文件读取,提供角色匹配与查询接口",
6
+ "dependencies": [],
7
+ "provides": ["provider:role-registry"],
8
+ "config": {}
9
+ }
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Provider: State Store
3
+ *
4
+ * Wraps the StateStore runtime module to provide unified state and task data access.
5
+ * Implements the ProviderPlugin interface from plugin-interface.js.
6
+ *
7
+ * Capabilities:
8
+ * - get(key) read arbitrary state via dot-notation key
9
+ * - getTasks() parse task.md into a structured task list
10
+ * - set(key, value) write state
11
+ * - delete(key) remove a state key
12
+ * - keys() list all stored keys
13
+ * - subscribe(key, cb) watch for changes on a key
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ var path = require('path');
19
+ var fs = require('fs');
20
+ var { ProviderPlugin } = require('../../contracts/plugin-interface');
21
+ var { StateStore, FileSystemAdapter } = require('../../runtime/state-store');
22
+
23
+ /**
24
+ * Minimal YAML-like parser for task.md
25
+ * Extracts the task table rows (WP-xxx entries) and status info.
26
+ */
27
+ function parseTaskMarkdown(content) {
28
+ var lines = content.split('\n');
29
+ var tasks = [];
30
+ var stats = { total: 0, completed: 0, inProgress: 0, pending: 0 };
31
+
32
+ // Find the table header row that starts with | WP |
33
+ var tableStarted = false;
34
+ var headerSkipped = false;
35
+ var separatorSkipped = false;
36
+
37
+ for (var i = 0; i < lines.length; i++) {
38
+ var line = lines[i];
39
+
40
+ if (!tableStarted) {
41
+ if (line.indexOf('| WP ') === 0 || line.indexOf('| WP\t') === 0) {
42
+ tableStarted = true;
43
+ headerSkipped = true; // this line IS the header, already skipped by continue
44
+ }
45
+ continue;
46
+ }
47
+
48
+ // The first line after tableStarted is the header - skip it
49
+ if (!headerSkipped) {
50
+ headerSkipped = true;
51
+ continue;
52
+ }
53
+
54
+ // The second line is the separator (|---|---|...) - skip it
55
+ if (!separatorSkipped) {
56
+ separatorSkipped = true;
57
+ continue;
58
+ }
59
+
60
+ // Parse data rows
61
+ var trimmed = line.trim();
62
+ if (!trimmed || trimmed.indexOf('|') !== 0) {
63
+ // End of table
64
+ break;
65
+ }
66
+
67
+ var cells = trimmed.split('|').filter(function (c) { return c.trim() !== ''; });
68
+ if (cells.length < 2) continue;
69
+
70
+ var wpId = cells[0].trim();
71
+ if (!wpId.match(/^WP-\d+$/)) continue;
72
+
73
+ var title = cells.length > 1 ? cells[1].trim() : '';
74
+ var statusCell = cells.length > 2 ? cells[2].trim() : '';
75
+ var phase = cells.length > 3 ? cells[3].trim() : '';
76
+ var priority = cells.length > 4 ? cells[4].trim() : '';
77
+ var deps = cells.length > 5 ? cells[5].trim() : '';
78
+ var estimate = cells.length > 6 ? cells[6].trim() : '';
79
+
80
+ var status = 'pending';
81
+ if (statusCell.indexOf('完成') !== -1 || statusCell.indexOf('Completed') !== -1) {
82
+ status = 'completed';
83
+ } else if (statusCell.indexOf('进行') !== -1 || statusCell.indexOf('In Progress') !== -1) {
84
+ status = 'in_progress';
85
+ } else if (statusCell.indexOf('待开始') !== -1 || statusCell.indexOf('Pending') !== -1) {
86
+ status = 'pending';
87
+ }
88
+
89
+ stats.total++;
90
+ if (status === 'completed') stats.completed++;
91
+ else if (status === 'in_progress') stats.inProgress++;
92
+ else stats.pending++;
93
+
94
+ tasks.push({
95
+ id: wpId,
96
+ title: title,
97
+ status: status,
98
+ phase: phase,
99
+ priority: priority,
100
+ dependencies: deps ? deps.split(',').map(function (d) { return d.trim(); }) : [],
101
+ estimate: estimate,
102
+ });
103
+ }
104
+
105
+ return { tasks: tasks, stats: stats };
106
+ }
107
+
108
+ /**
109
+ * StateStoreProvider - provides state access and task parsing
110
+ */
111
+ class StateStoreProvider extends ProviderPlugin {
112
+ constructor() {
113
+ super();
114
+ this.name = 'provider-state-store';
115
+ this.version = '1.0.0';
116
+ this.description = 'State Store Provider';
117
+ this.provides = 'provider:state-store';
118
+ this.dependencies = {};
119
+
120
+ /** @type {StateStore|null} */
121
+ this._store = null;
122
+ /** @type {string} */
123
+ this._projectRoot = '';
124
+ }
125
+
126
+ /**
127
+ * Called when the plugin is activated.
128
+ * Initializes the StateStore with the project root path.
129
+ *
130
+ * @param {PluginContext} context
131
+ */
132
+ async onActivate(context) {
133
+ this._projectRoot = this._resolveProjectRoot();
134
+ var stateFilePath = path.join(this._projectRoot, '.claude-state');
135
+ this._store = new StateStore({ filePath: stateFilePath });
136
+ }
137
+
138
+ /**
139
+ * Factory method - returns the provider instance (this provider itself).
140
+ *
141
+ * @param {PluginContext} context
142
+ * @returns {Promise<object>} the state store provider API
143
+ */
144
+ async factory(context) {
145
+ var self = this;
146
+
147
+ return {
148
+ /**
149
+ * Get a value by dot-notation key from the state store.
150
+ * @param {string} key - e.g. 'harness.state'
151
+ * @returns {Promise<*|undefined>}
152
+ */
153
+ get: function (key) {
154
+ return self._store.get(key);
155
+ },
156
+
157
+ /**
158
+ * Set a value by dot-notation key.
159
+ * @param {string} key
160
+ * @param {*} value
161
+ * @returns {Promise<void>}
162
+ */
163
+ set: function (key, value) {
164
+ return self._store.set(key, value);
165
+ },
166
+
167
+ /**
168
+ * Delete a key from the state store.
169
+ * @param {string} key
170
+ * @returns {Promise<void>}
171
+ */
172
+ delete: function (key) {
173
+ return self._store.delete(key);
174
+ },
175
+
176
+ /**
177
+ * List all stored keys.
178
+ * @returns {Promise<string[]>}
179
+ */
180
+ keys: function () {
181
+ return self._store.keys();
182
+ },
183
+
184
+ /**
185
+ * Subscribe to changes on a specific key.
186
+ * @param {string} key
187
+ * @param {Function} callback - callback(key, oldValue, newValue)
188
+ * @returns {{ unsubscribe: Function }}
189
+ */
190
+ subscribe: function (key, callback) {
191
+ return self._store.subscribe(key, callback);
192
+ },
193
+
194
+ /**
195
+ * Parse task.md into a structured task list.
196
+ * @returns {Promise<{ tasks: object[], stats: object }>}
197
+ */
198
+ getTasks: function () {
199
+ return self._parseTasks();
200
+ },
201
+
202
+ /**
203
+ * Get the raw state store instance for advanced usage.
204
+ * @returns {StateStore}
205
+ */
206
+ getStore: function () {
207
+ return self._store;
208
+ },
209
+ };
210
+ }
211
+
212
+ /**
213
+ * Parse the task.md file.
214
+ * @returns {Promise<{ tasks: object[], stats: object }>}
215
+ */
216
+ async _parseTasks() {
217
+ var taskFile = path.join(this._projectRoot, 'task.md');
218
+ try {
219
+ var content = fs.readFileSync(taskFile, 'utf-8');
220
+ return parseTaskMarkdown(content);
221
+ } catch (err) {
222
+ return { tasks: [], stats: { total: 0, completed: 0, inProgress: 0, pending: 0 } };
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Resolve the project root directory.
228
+ * Walks up from cwd to find a directory containing task.md or .claude/.
229
+ * @returns {string}
230
+ */
231
+ _resolveProjectRoot() {
232
+ var dir = process.cwd();
233
+ for (var i = 0; i < 10; i++) {
234
+ if (fs.existsSync(path.join(dir, 'task.md'))) return dir;
235
+ if (fs.existsSync(path.join(dir, '.claude'))) return dir;
236
+ var parent = path.dirname(dir);
237
+ if (parent === dir) break;
238
+ dir = parent;
239
+ }
240
+ return process.cwd();
241
+ }
242
+ }
243
+
244
+ module.exports = StateStoreProvider;
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "provider-state-store",
3
+ "version": "1.0.0",
4
+ "type": "provider",
5
+ "description": "状态存储 Provider - 包装 StateStore 运行时模块,提供统一的状态和任务数据访问接口",
6
+ "dependencies": [],
7
+ "provides": ["provider:state-store"],
8
+ "config": {}
9
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "daemon": {
3
+ "mode": "background"
4
+ },
5
+ "heartbeat_dir": ".claude-daemon",
6
+ "check_interval_sec": 30,
7
+ "timeouts": {
8
+ "task_stalled_min": 20,
9
+ "session_stalled_min": 30,
10
+ "restart_cooldown_min": 2,
11
+ "marker_window_min": 5
12
+ },
13
+ "retry": {
14
+ "max_retries": 3,
15
+ "timeout_scale": [1.0, 1.33, 2.0],
16
+ "cooldown_min": [0, 2, 5]
17
+ },
18
+ "circuit_breaker": {
19
+ "consecutive_failures_threshold": 3,
20
+ "total_retries_multiplier": 2,
21
+ "cooldown_after_break_min": 15
22
+ },
23
+ "process": {
24
+ "kill_timeout_sec": 10,
25
+ "restart_command": "claude --skill agent-dispatcher"
26
+ },
27
+ "logging": {
28
+ "level": "info",
29
+ "max_file_size_mb": 10,
30
+ "max_files": 3
31
+ }
32
+ }