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,15 @@
1
+ {
2
+ "name": "provider-loop-engine",
3
+ "version": "1.0.0",
4
+ "type": "provider",
5
+ "description": "Agentic Loop 决策状态机 Provider - Observe/Think/Act/Reflect/Decide 循环核心,复用 state-store 持久化",
6
+ "dependencies": ["provider:state-store", "provider:watchdog"],
7
+ "provides": ["provider:loop-engine"],
8
+ "config": {
9
+ "max_iterations": 6,
10
+ "max_round_time_ms": 600000,
11
+ "max_wall_time_ms": 3600000,
12
+ "divergence_threshold": 3,
13
+ "proximity_goal": 0.9
14
+ }
15
+ }
@@ -0,0 +1,510 @@
1
+ /**
2
+ * Provider: Memory Store
3
+ *
4
+ * Wraps the agents/memories/ directory to provide role memory data access.
5
+ * Implements the ProviderPlugin interface from plugin-interface.js.
6
+ *
7
+ * Capabilities:
8
+ * - getByRole(roleName) return memory data for a specific role
9
+ * - setByRole(roleName, data) write/update memory data for a role
10
+ * - list() list all available memory entries
11
+ * - getByPath(filePath) read a specific memory file by relative path
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ var path = require('path');
17
+ var fs = require('fs');
18
+ var sharedTokenize = require('../../runtime/text-tokenize');
19
+ var { ProviderPlugin } = require('../../contracts/plugin-interface');
20
+
21
+ /**
22
+ * MemoryStoreProvider - provides memory data access
23
+ */
24
+ class MemoryStoreProvider extends ProviderPlugin {
25
+ constructor() {
26
+ super();
27
+ this.name = 'provider-memory-store';
28
+ this.version = '1.0.0';
29
+ this.description = 'Memory Store Provider';
30
+ this.provides = 'provider:memory-store';
31
+ this.dependencies = {};
32
+
33
+ /** @type {string} absolute path to memories directory */
34
+ this._memoriesDir = '';
35
+ /** @type {Map<string, object>} cache of loaded memories */
36
+ this._cache = new Map();
37
+ }
38
+
39
+ /**
40
+ * Activate - set up the memories directory path.
41
+ * @param {PluginContext} context
42
+ */
43
+ async onActivate(context) {
44
+ var projectRoot = this._resolveProjectRoot();
45
+ this._memoriesDir = path.join(projectRoot, '.claude', 'agents', 'memories');
46
+
47
+ // Ensure the directory exists
48
+ if (!fs.existsSync(this._memoriesDir)) {
49
+ fs.mkdirSync(this._memoriesDir, { recursive: true });
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Factory - return the provider API.
55
+ * @param {PluginContext} context
56
+ * @returns {Promise<object>}
57
+ */
58
+ async factory(context) {
59
+ var self = this;
60
+
61
+ return {
62
+ /**
63
+ * Get memory data for a specific role.
64
+ * Looks for {roleName}.md in the memories directory.
65
+ *
66
+ * @param {string} roleName - role identifier (e.g. 'coordinator')
67
+ * @returns {Promise<{ roleName: string, content: string, filePath: string, exists: boolean }>}
68
+ */
69
+ getByRole: function (roleName) {
70
+ return self._getByRole(roleName);
71
+ },
72
+
73
+ /**
74
+ * Write memory data for a specific role.
75
+ * Creates or overwrites the memory file for the role.
76
+ *
77
+ * @param {string} roleName
78
+ * @param {string|object} data - memory content (string) or structured data to serialize
79
+ * @returns {Promise<{ roleName: string, filePath: string, written: boolean }>}
80
+ */
81
+ setByRole: function (roleName, data) {
82
+ return self._setByRole(roleName, data);
83
+ },
84
+
85
+ /**
86
+ * List all available memory entries.
87
+ * @returns {Promise<{ name: string, roleName: string, filePath: string, size: number, modified: string }[]>}
88
+ */
89
+ list: function () {
90
+ return self._list();
91
+ },
92
+
93
+ /**
94
+ * Read a memory file by its relative path within the memories directory.
95
+ * @param {string} relPath - relative path (e.g. 'coordinator.md')
96
+ * @returns {Promise<{ content: string, filePath: string, exists: boolean }>}
97
+ */
98
+ getByPath: function (relPath) {
99
+ return self._getByPath(relPath);
100
+ },
101
+
102
+ /**
103
+ * WP-D5:按 query 召回指定角色记忆的相关条目(关键词打分,替代整文件灌入)。
104
+ * 打分:标题命中 ×3 / 标签 ×2 / 正文 ×1(中文按字符 bigram,拉丁按词)。
105
+ * @param {string} roleName 角色名
106
+ * @param {string} query 查询词(如 "mysql 索引 优化")
107
+ * @param {number} [topK] 返回条数上限(默认 3)
108
+ * @returns {Promise<{ roleName: string, query: string, total: number,
109
+ * results: Array<{ title: string, tag: string, score: number, block: string }> }>}
110
+ */
111
+ recall: function (roleName, query, topK) {
112
+ return Promise.resolve(self._recall(roleName, query, topK));
113
+ },
114
+ };
115
+ }
116
+
117
+ /**
118
+ * WP-D5:检索分词(委托共享模块 plugins/runtime/text-tokenize.js——WP-S4 提取,
119
+ * 与 executor 精读 retry 共用同一分词口径)
120
+ * @param {string} text
121
+ * @returns {string[]}
122
+ */
123
+ _tokenize(text) {
124
+ return sharedTokenize.tokenize(text);
125
+ }
126
+
127
+ /**
128
+ * WP-D5:把记忆 markdown 按条目切块(### [tag] title 为边界,到下一个 ### / --- / EOF)。
129
+ * @param {string} content 记忆文件全文
130
+ * @returns {Array<{ title: string, tag: string, block: string }>}
131
+ */
132
+ _splitExperienceBlocks(content) {
133
+ var blocks = [];
134
+ var lines = String(content || '').split(/\r?\n/);
135
+ var current = null;
136
+ var buf = [];
137
+ var reHead = /^###\s*\[([^\]]*)\]\s*(.*)$/;
138
+ for (var i = 0; i < lines.length; i++) {
139
+ var line = lines[i];
140
+ var m = line.match(reHead);
141
+ if (m) {
142
+ if (current) blocks.push({ title: current.title, tag: current.tag, block: buf.join('\n').trim() });
143
+ current = { tag: (m[1] || '').trim(), title: (m[2] || '').trim() };
144
+ buf = [line];
145
+ continue;
146
+ }
147
+ if (current) {
148
+ // 条目终止:分隔线(第二条 --- 之后区域)或下一个标题由上方捕获
149
+ if (/^---\s*$/.test(line) && buf.join('\n').indexOf('---') !== -1) {
150
+ // 到达经验区末尾的分隔线:收尾
151
+ blocks.push({ title: current.title, tag: current.tag, block: buf.join('\n').trim() });
152
+ current = null;
153
+ buf = [];
154
+ continue;
155
+ }
156
+ buf.push(line);
157
+ }
158
+ }
159
+ if (current) blocks.push({ title: current.title, tag: current.tag, block: buf.join('\n').trim() });
160
+ return blocks;
161
+ }
162
+
163
+ /**
164
+ * WP-D5:关键词召回。
165
+ * @param {string} roleName
166
+ * @param {string} query
167
+ * @param {number} [topK=3]
168
+ * @returns {{ roleName: string, query: string, total: number, results: Array }}
169
+ */
170
+ _recall(roleName, query, topK) {
171
+ var k = (typeof topK === 'number' && topK > 0) ? Math.floor(topK) : 3;
172
+ var safeName = String(roleName || '').replace(/[^a-zA-Z0-9_\-]/g, '');
173
+ var content = '';
174
+ try {
175
+ var cached = this._cache.get(safeName);
176
+ content = cached ? cached.content : fs.readFileSync(
177
+ path.join(this._memoriesDir, safeName + '.md'), 'utf-8');
178
+ } catch (_e) {
179
+ return { roleName: safeName, query: query || '', total: 0, results: [] };
180
+ }
181
+ var qTokens = this._tokenize(query);
182
+ if (qTokens.length === 0) {
183
+ return { roleName: safeName, query: query || '', total: 0, results: [] };
184
+ }
185
+ var blocks = this._splitExperienceBlocks(content);
186
+ var scored = [];
187
+ for (var b = 0; b < blocks.length; b++) {
188
+ var blk = blocks[b];
189
+ var titleTokens = this._tokenize(blk.title);
190
+ var tagTokens = this._tokenize(blk.tag);
191
+ var bodyTokens = this._tokenize(blk.block);
192
+ var score = 0;
193
+ for (var q = 0; q < qTokens.length; q++) {
194
+ var qt = qTokens[q];
195
+ if (titleTokens.indexOf(qt) !== -1) score += 3;
196
+ if (tagTokens.indexOf(qt) !== -1) score += 2;
197
+ if (bodyTokens.indexOf(qt) !== -1) score += 1;
198
+ }
199
+ if (score > 0) scored.push({ title: blk.title, tag: blk.tag, score: score, block: blk.block });
200
+ }
201
+ scored.sort(function (a, b) { return b.score - a.score; });
202
+ return {
203
+ roleName: safeName,
204
+ query: query || '',
205
+ total: scored.length,
206
+ results: scored.slice(0, k),
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Get memory data for a role.
212
+ * @param {string} roleName
213
+ * @returns {Promise<object>}
214
+ */
215
+ async _getByRole(roleName) {
216
+ // Sanitize roleName to prevent path traversal
217
+ var safeName = roleName.replace(/[^a-zA-Z0-9_\-]/g, '');
218
+ var fileName = safeName + '.md';
219
+ var filePath = path.join(this._memoriesDir, fileName);
220
+
221
+ // Check cache first
222
+ if (this._cache.has(safeName)) {
223
+ var cached = this._cache.get(safeName);
224
+ return {
225
+ roleName: safeName,
226
+ content: cached.content,
227
+ filePath: filePath,
228
+ exists: true,
229
+ metadata: cached.metadata,
230
+ };
231
+ }
232
+
233
+ try {
234
+ var content = fs.readFileSync(filePath, 'utf-8');
235
+ var metadata = this._parseMemoryMetadata(content);
236
+
237
+ // Cache the result
238
+ this._cache.set(safeName, { content: content, metadata: metadata });
239
+
240
+ return {
241
+ roleName: safeName,
242
+ content: content,
243
+ filePath: filePath,
244
+ exists: true,
245
+ metadata: metadata,
246
+ };
247
+ } catch (err) {
248
+ return {
249
+ roleName: safeName,
250
+ content: '',
251
+ filePath: filePath,
252
+ exists: false,
253
+ metadata: {},
254
+ };
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Write memory data for a role.
260
+ * @param {string} roleName
261
+ * @param {string|object} data
262
+ * @returns {Promise<object>}
263
+ */
264
+ async _setByRole(roleName, data) {
265
+ var safeName = roleName.replace(/[^a-zA-Z0-9_\-]/g, '');
266
+ var fileName = safeName + '.md';
267
+ var filePath = path.join(this._memoriesDir, fileName);
268
+
269
+ var content;
270
+ if (typeof data === 'string') {
271
+ content = data;
272
+ } else if (typeof data === 'object' && data !== null) {
273
+ // Serialize structured data to markdown-like format
274
+ content = this._serializeMemory(safeName, data);
275
+ } else {
276
+ content = String(data);
277
+ }
278
+
279
+ // Ensure directory exists
280
+ var dir = path.dirname(filePath);
281
+ if (!fs.existsSync(dir)) {
282
+ fs.mkdirSync(dir, { recursive: true });
283
+ }
284
+
285
+ fs.writeFileSync(filePath, content, 'utf-8');
286
+
287
+ // Update cache
288
+ var metadata = this._parseMemoryMetadata(content);
289
+ this._cache.set(safeName, { content: content, metadata: metadata });
290
+
291
+ return {
292
+ roleName: safeName,
293
+ filePath: filePath,
294
+ written: true,
295
+ };
296
+ }
297
+
298
+ /**
299
+ * List all memory files.
300
+ * @returns {Promise<object[]>}
301
+ */
302
+ async _list() {
303
+ var results = [];
304
+
305
+ try {
306
+ var files = fs.readdirSync(this._memoriesDir);
307
+ for (var i = 0; i < files.length; i++) {
308
+ var file = files[i];
309
+ if (!file.match(/\.(md|yaml|yml|json)$/)) continue;
310
+
311
+ var fullPath = path.join(this._memoriesDir, file);
312
+ try {
313
+ var stat = fs.statSync(fullPath);
314
+ var roleName = file.replace(/\.[^/.]+$/, '');
315
+
316
+ results.push({
317
+ name: file,
318
+ roleName: roleName,
319
+ filePath: fullPath,
320
+ size: stat.size,
321
+ modified: stat.mtime.toISOString(),
322
+ });
323
+ } catch (statErr) {
324
+ // Skip files that can't be stat'd
325
+ }
326
+ }
327
+ } catch (err) {
328
+ // Directory doesn't exist or can't be read
329
+ }
330
+
331
+ return results;
332
+ }
333
+
334
+ /**
335
+ * Read a memory file by relative path.
336
+ * @param {string} relPath
337
+ * @returns {Promise<object>}
338
+ */
339
+ async _getByPath(relPath) {
340
+ // Sanitize to prevent path traversal
341
+ var safePath = relPath.replace(/\.\./g, '').replace(/[\\]/g, '/');
342
+ var filePath = path.join(this._memoriesDir, safePath);
343
+
344
+ // Ensure the resolved path is still within the memories directory
345
+ if (!filePath.startsWith(this._memoriesDir)) {
346
+ return { content: '', filePath: safePath, exists: false };
347
+ }
348
+
349
+ try {
350
+ var content = fs.readFileSync(filePath, 'utf-8');
351
+ return { content: content, filePath: filePath, exists: true };
352
+ } catch (err) {
353
+ return { content: '', filePath: safePath, exists: false };
354
+ }
355
+ }
356
+
357
+ /**
358
+ * Parse metadata from a memory markdown file.
359
+ * Extracts role name, creation date, usage, and experience count.
360
+ * @param {string} content
361
+ * @returns {object}
362
+ */
363
+ _parseMemoryMetadata(content) {
364
+ var metadata = {};
365
+ var lines = content.split('\n');
366
+
367
+ for (var i = 0; i < lines.length; i++) {
368
+ var line = lines[i];
369
+
370
+ // Role name from heading
371
+ var headingMatch = line.match(/^#\s+(.+)角色记忆库/);
372
+ if (headingMatch) {
373
+ metadata.roleTitle = headingMatch[1].trim();
374
+ continue;
375
+ }
376
+
377
+ // Role from metadata line
378
+ var roleMatch = line.match(/^>\s*角色:\s*(.+)/);
379
+ if (roleMatch) {
380
+ metadata.role = roleMatch[1].trim();
381
+ continue;
382
+ }
383
+
384
+ // Creation date
385
+ var dateMatch = line.match(/^>\s*创建日期:\s*(.+)/);
386
+ if (dateMatch) {
387
+ metadata.createdDate = dateMatch[1].trim();
388
+ continue;
389
+ }
390
+
391
+ // Usage
392
+ var usageMatch = line.match(/^>\s*用途:\s*(.+)/);
393
+ if (usageMatch) {
394
+ metadata.usage = usageMatch[1].trim();
395
+ continue;
396
+ }
397
+
398
+ // Experience count
399
+ var expMatch = line.match(/^-?\s*总经验数:\s*(\d+)/);
400
+ if (expMatch) {
401
+ metadata.experienceCount = parseInt(expMatch[1], 10);
402
+ continue;
403
+ }
404
+
405
+ // Last update
406
+ var updateMatch = line.match(/^-?\s*最后更新:\s*(.+)/);
407
+ if (updateMatch) {
408
+ metadata.lastUpdate = updateMatch[1].trim();
409
+ continue;
410
+ }
411
+
412
+ // Total tasks
413
+ var taskMatch = line.match(/^-?\s*累计执行任务:\s*(\d+)/);
414
+ if (taskMatch) {
415
+ metadata.totalTasks = parseInt(taskMatch[1], 10);
416
+ continue;
417
+ }
418
+ }
419
+
420
+ return metadata;
421
+ }
422
+
423
+ /**
424
+ * Serialize structured data to a memory markdown file.
425
+ * @param {string} roleName
426
+ * @param {object} data
427
+ * @returns {string}
428
+ */
429
+ _serializeMemory(roleName, data) {
430
+ var lines = [];
431
+ var title = data.title || roleName;
432
+ var role = data.role || roleName;
433
+ var createdDate = data.createdDate || new Date().toISOString().split('T')[0];
434
+ var usage = data.usage || '';
435
+ var experienceCount = data.experienceCount || 0;
436
+ var lastUpdate = data.lastUpdate || createdDate;
437
+ var totalTasks = data.totalTasks || 0;
438
+ var experiences = data.experiences || [];
439
+ var notes = data.notes || '';
440
+
441
+ lines.push('# ' + title + '角色记忆库');
442
+ lines.push('');
443
+ lines.push('> 角色: ' + role);
444
+ lines.push('> 创建日期: ' + createdDate);
445
+ lines.push('> 用途: ' + usage);
446
+ lines.push('');
447
+ lines.push('## 统计');
448
+ lines.push('');
449
+ lines.push('- 总经验数: ' + experienceCount);
450
+ lines.push('- 最后更新: ' + lastUpdate);
451
+ lines.push('- 累计执行任务: ' + totalTasks + ' 次');
452
+ lines.push('');
453
+ lines.push('---');
454
+ lines.push('');
455
+ lines.push('## 经验列表');
456
+ lines.push('');
457
+
458
+ if (experiences.length > 0) {
459
+ for (var i = 0; i < experiences.length; i++) {
460
+ var exp = experiences[i];
461
+ lines.push('### [' + (exp.tag || '') + '] ' + (exp.title || ''));
462
+ lines.push('');
463
+ if (exp.description) {
464
+ lines.push('**问题描述**: ' + exp.description);
465
+ lines.push('');
466
+ }
467
+ if (exp.solution) {
468
+ lines.push('**解决方案**: ' + exp.solution);
469
+ lines.push('');
470
+ }
471
+ if (exp.source) {
472
+ lines.push('**来源工作包**: ' + exp.source);
473
+ }
474
+ if (exp.date) {
475
+ lines.push('**记录日期**: ' + exp.date);
476
+ }
477
+ lines.push('');
478
+ }
479
+ }
480
+
481
+ lines.push('---');
482
+ lines.push('');
483
+ lines.push('## 注意事项');
484
+ lines.push('');
485
+
486
+ if (notes) {
487
+ lines.push(notes);
488
+ }
489
+
490
+ return lines.join('\n');
491
+ }
492
+
493
+ /**
494
+ * Resolve the project root directory.
495
+ * @returns {string}
496
+ */
497
+ _resolveProjectRoot() {
498
+ var dir = process.cwd();
499
+ for (var i = 0; i < 10; i++) {
500
+ if (fs.existsSync(path.join(dir, 'task.md'))) return dir;
501
+ if (fs.existsSync(path.join(dir, '.claude'))) return dir;
502
+ var parent = path.dirname(dir);
503
+ if (parent === dir) break;
504
+ dir = parent;
505
+ }
506
+ return process.cwd();
507
+ }
508
+ }
509
+
510
+ module.exports = MemoryStoreProvider;
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "provider-memory-store",
3
+ "version": "1.0.0",
4
+ "type": "provider",
5
+ "description": "记忆存储 Provider - 包装 agents/memories/ 目录读写,提供角色记忆数据访问接口",
6
+ "dependencies": [],
7
+ "provides": ["provider:memory-store"],
8
+ "config": {}
9
+ }