doukui 0.8.0 → 0.9.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/README.en.md +85 -18
- package/README.md +8 -8
- package/bin/commands/help.js +2 -0
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +2 -0
- package/package.json +1 -1
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +64 -15
- package/plugins/core/hook-skill-gate/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
- package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +5 -177
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
- package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
- package/plugins/core/skill-agentic-loop/plugin.json +1 -1
- package/plugins/core/skill-agentic-loop/skill.md +123 -324
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +22 -22
- package/plugins/core/skill-experience-logger/plugin.json +1 -1
- package/plugins/core/skill-human-checkpoint/skill.md +1 -0
- package/plugins/core/skill-split-work-package/plugin.json +1 -1
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +1 -139
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -36
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +21 -3
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/plugins/contracts/capabilities.js +0 -268
- package/plugins/core/provider-memory-store/index.js +0 -510
- package/plugins/core/provider-memory-store/plugin.json +0 -9
- package/plugins/core/provider-state-store/index.js +0 -244
- package/plugins/core/provider-state-store/plugin.json +0 -9
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
- package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
- package/plugins/core/provider-watchdog/index.js +0 -151
- package/plugins/core/provider-watchdog/plugin.json +0 -13
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
- package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
- package/plugins/core/skill-watchdog-manager/skill.md +0 -143
- package/plugins/core/validator-doc-sync/index.js +0 -248
- package/plugins/core/validator-doc-sync/plugin.json +0 -12
- package/plugins/core/validator-work-package/index.js +0 -300
- package/plugins/core/validator-work-package/plugin.json +0 -12
- package/plugins/runtime/audit-logger.js +0 -311
- package/plugins/runtime/build-cli.js +0 -89
- package/plugins/runtime/event-bus.js +0 -207
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- package/plugins/runtime/sandbox-context.js +0 -235
- package/plugins/runtime/sandbox-manager.js +0 -609
- package/plugins/runtime/sandbox-worker.js +0 -215
- package/plugins/runtime/text-tokenize.js +0 -24
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -1,510 +0,0 @@
|
|
|
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;
|