@crewx/memory 0.1.23-rc.18 → 0.1.23-rc.180
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +3 -340
- package/dist/src/engine.d.ts +25 -1
- package/dist/src/engine.js +94 -1009
- package/dist/src/mindmap.d.ts +1 -1
- package/dist/src/mindmap.js +26 -526
- package/dist/src/parser.d.ts +1 -1
- package/dist/src/parser.js +1 -7
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -15
- package/package.json +4 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/src/engine.d.ts.map +0 -1
- package/dist/src/engine.js.map +0 -1
- package/dist/src/mindmap.d.ts.map +0 -1
- package/dist/src/mindmap.js.map +0 -1
- package/dist/src/parser.d.ts.map +0 -1
- package/dist/src/parser.js.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js.map +0 -1
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,83 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.main = main;
|
|
38
|
-
const fs = __importStar(require("fs"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
const engine_1 = require("./src/engine");
|
|
41
|
-
const types_1 = require("./src/types");
|
|
42
|
-
const mindmap_1 = require("./src/mindmap");
|
|
43
|
-
let PKG_VERSION = 'unknown';
|
|
44
|
-
try {
|
|
45
|
-
const _pkgPath = fs.existsSync(path.join(__dirname, 'package.json'))
|
|
46
|
-
? path.join(__dirname, 'package.json')
|
|
47
|
-
: path.join(__dirname, '..', 'package.json');
|
|
48
|
-
const _pkg = JSON.parse(fs.readFileSync(_pkgPath, 'utf-8'));
|
|
49
|
-
if (_pkg?.version)
|
|
50
|
-
PKG_VERSION = String(_pkg.version);
|
|
51
|
-
}
|
|
52
|
-
catch { }
|
|
53
|
-
function readStdin() {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
const chunks = [];
|
|
56
|
-
process.stdin.on('data', (chunk) => chunks.push(chunk));
|
|
57
|
-
process.stdin.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8').trim()));
|
|
58
|
-
process.stdin.on('error', reject);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async function loadTracer() {
|
|
62
|
-
try {
|
|
63
|
-
return await Promise.resolve().then(() => __importStar(require('@crewx/shared/skill-tracer')));
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function showDetailedUsage() {
|
|
70
|
-
const skillMd = path.join(__dirname, '..', 'SKILL.md');
|
|
71
|
-
if (fs.existsSync(skillMd)) {
|
|
72
|
-
process.stdout.write(fs.readFileSync(skillMd, 'utf-8'));
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
console.log('No SKILL.md found. Use --help for usage.');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function printUsage() {
|
|
79
|
-
console.log(`
|
|
80
|
-
@crewx/memory@${PKG_VERSION} - Markdown-based long-term memory for AI agents
|
|
2
|
+
"use strict";var w=exports&&exports.__createBinding||(Object.create?(function(s,r,i,e){if(e===void 0)e=i;var t=Object.getOwnPropertyDescriptor(r,i);if(!t||("get"in t?!r.__esModule:t.writable||t.configurable)){t={enumerable:true,get:function(){return r[i]}}}Object.defineProperty(s,e,t)}):(function(s,r,i,e){if(e===void 0)e=i;s[e]=r[i]}));var v=exports&&exports.__setModuleDefault||(Object.create?(function(s,r){Object.defineProperty(s,"default",{enumerable:true,value:r})}):function(s,r){s["default"]=r});var y=exports&&exports.__importStar||(function(){var s=function(r){s=Object.getOwnPropertyNames||function(i){var e=[];for(var t in i)if(Object.prototype.hasOwnProperty.call(i,t))e[e.length]=t;return e};return s(r)};return function(r){if(r&&r.__esModule)return r;var i={};if(r!=null){for(var e=s(r),t=0;t<e.length;t++)if(e[t]!=="default")w(i,r,e[t])}v(i,r);return i}})();Object.defineProperty(exports,"__esModule",{value:true});exports.main=b;const p=y(require("fs"));const f=y(require("path"));const k=require("./src/engine");const x=require("./src/types");const S=require("./src/mindmap");let _="unknown";try{const s=p.existsSync(f.join(__dirname,"package.json"))?f.join(__dirname,"package.json"):f.join(__dirname,"..","package.json");const r=JSON.parse(p.readFileSync(s,"utf-8"));if(r?.version)_=String(r.version)}catch{}function q(){const s=[];let r;let i;const e=new Promise((a,l)=>{r=a;i=l});const t=a=>s.push(a);const n=()=>r(Buffer.concat(s).toString("utf-8").trim());const o=a=>i(a);process.stdin.on("data",t);process.stdin.on("end",n);process.stdin.on("error",o);const g=()=>{process.stdin.off("data",t);process.stdin.off("end",n);process.stdin.off("error",o);process.stdin.pause();if(typeof process.stdin.unref==="function")process.stdin.unref()};return{body:e,release:g}}async function E(){try{return await Promise.resolve().then(()=>y(require("@crewx/shared/skill-tracer")))}catch{return null}}function O(){const s=f.join(__dirname,"..","SKILL.md");if(p.existsSync(s)){process.stdout.write(p.readFileSync(s,"utf-8"))}else{console.log("No SKILL.md found. Use --help for usage.")}}function h(){console.log(`
|
|
3
|
+
@crewx/memory@${_} - Markdown-based long-term memory for AI agents
|
|
81
4
|
|
|
82
5
|
Usage:
|
|
83
6
|
memory <command> <agent_id> [args]
|
|
@@ -110,264 +33,4 @@ Examples:
|
|
|
110
33
|
memory get myagent PWN3qt
|
|
111
34
|
|
|
112
35
|
For detailed usage guide: memory usage
|
|
113
|
-
`);
|
|
114
|
-
}
|
|
115
|
-
const ALIASES = {
|
|
116
|
-
read: 'get',
|
|
117
|
-
rm: 'delete',
|
|
118
|
-
ls: 'recent',
|
|
119
|
-
};
|
|
120
|
-
const BOOLEAN_FLAGS = new Set([
|
|
121
|
-
'help', 'force', 'verbose', 'full', 'important', 'no-important', 'json', 'all', 'version',
|
|
122
|
-
]);
|
|
123
|
-
function parseArgs(args) {
|
|
124
|
-
const result = { positional: [], options: {} };
|
|
125
|
-
for (let i = 0; i < args.length; i++) {
|
|
126
|
-
const arg = args[i];
|
|
127
|
-
if (arg === '-h') {
|
|
128
|
-
result.options['help'] = true;
|
|
129
|
-
}
|
|
130
|
-
else if (arg.startsWith('--')) {
|
|
131
|
-
const eqIdx = arg.indexOf('=');
|
|
132
|
-
if (eqIdx !== -1) {
|
|
133
|
-
const key = arg.slice(2, eqIdx);
|
|
134
|
-
const value = arg.slice(eqIdx + 1);
|
|
135
|
-
result.options[key] = value;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
const key = arg.slice(2);
|
|
139
|
-
if (!BOOLEAN_FLAGS.has(key)) {
|
|
140
|
-
const nextArg = args[i + 1];
|
|
141
|
-
if (nextArg !== undefined && !nextArg.startsWith('--') && nextArg !== '-h') {
|
|
142
|
-
result.options[key] = nextArg;
|
|
143
|
-
i++;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
result.options[key] = true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
result.options[key] = true;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
result.positional.push(arg);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
}
|
|
160
|
-
async function main(inputArgs) {
|
|
161
|
-
const args = inputArgs ?? process.argv.slice(2);
|
|
162
|
-
const { positional, options } = parseArgs(args);
|
|
163
|
-
const [command, agentId, ...rest] = positional;
|
|
164
|
-
if (options.version) {
|
|
165
|
-
console.log(PKG_VERSION);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (options.help) {
|
|
169
|
-
printUsage();
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
if (command === 'usage') {
|
|
173
|
-
showDetailedUsage();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (command === 'help') {
|
|
177
|
-
printUsage();
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (!command) {
|
|
181
|
-
printUsage();
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const resolvedCommand = ALIASES[command] ?? command;
|
|
185
|
-
if (resolvedCommand === 'mindmap') {
|
|
186
|
-
const dataDir = process.env['MEMORY_DATA_DIR'] ?? path.resolve(process.cwd(), 'memory');
|
|
187
|
-
const mindmap = new mindmap_1.MindmapEngine(dataDir);
|
|
188
|
-
const subcommand = agentId;
|
|
189
|
-
const mAgentId = rest[0];
|
|
190
|
-
const mRest = rest.slice(1);
|
|
191
|
-
if (!subcommand) {
|
|
192
|
-
console.log('Usage: npx memory mindmap <subcommand> [agent_id] [args]');
|
|
193
|
-
console.log('');
|
|
194
|
-
console.log('Subcommands:');
|
|
195
|
-
console.log(' build <agent_id> - 그래프 빌드');
|
|
196
|
-
console.log(' show <agent_id> [--period=stm|mtm|ltm] [--format=mermaid|text] - 그래프 요약');
|
|
197
|
-
console.log(' related <agent_id> <memory_id> - 연결된 기억 조회');
|
|
198
|
-
console.log(' add <agent_id> <from_id> <to_id> [type] - 수동 연결 추가');
|
|
199
|
-
console.log(' remove <agent_id> <from_id> <to_id> - 연결 제거');
|
|
200
|
-
console.log(' html - 공용 HTML 생성');
|
|
201
|
-
console.log(' open [agent_id] - 브라우저에서 열기');
|
|
202
|
-
process.exit(1);
|
|
203
|
-
}
|
|
204
|
-
switch (subcommand) {
|
|
205
|
-
case 'build':
|
|
206
|
-
if (!mAgentId) {
|
|
207
|
-
console.log('Error: agent_id is required');
|
|
208
|
-
process.exit(1);
|
|
209
|
-
}
|
|
210
|
-
mindmap.build(mAgentId, options);
|
|
211
|
-
break;
|
|
212
|
-
case 'show':
|
|
213
|
-
if (!mAgentId) {
|
|
214
|
-
console.log('Error: agent_id is required');
|
|
215
|
-
process.exit(1);
|
|
216
|
-
}
|
|
217
|
-
mindmap.show(mAgentId, { period: options.period, format: options.format });
|
|
218
|
-
break;
|
|
219
|
-
case 'related':
|
|
220
|
-
if (!mAgentId || !mRest?.[0]) {
|
|
221
|
-
console.log('Error: agent_id and memory_id are required');
|
|
222
|
-
process.exit(1);
|
|
223
|
-
}
|
|
224
|
-
mindmap.related(mAgentId, mRest[0]);
|
|
225
|
-
break;
|
|
226
|
-
case 'add':
|
|
227
|
-
if (!mAgentId || !mRest?.[0] || !mRest?.[1]) {
|
|
228
|
-
console.log('Error: agent_id, from_id and to_id are required');
|
|
229
|
-
process.exit(1);
|
|
230
|
-
}
|
|
231
|
-
mindmap.add(mAgentId, mRest[0], mRest[1], mRest[2]);
|
|
232
|
-
break;
|
|
233
|
-
case 'remove':
|
|
234
|
-
if (!mAgentId || !mRest?.[0] || !mRest?.[1]) {
|
|
235
|
-
console.log('Error: agent_id, from_id and to_id are required');
|
|
236
|
-
process.exit(1);
|
|
237
|
-
}
|
|
238
|
-
mindmap.remove(mAgentId, mRest[0], mRest[1]);
|
|
239
|
-
break;
|
|
240
|
-
case 'html':
|
|
241
|
-
mindmap.html();
|
|
242
|
-
break;
|
|
243
|
-
case 'open':
|
|
244
|
-
mindmap.open(mAgentId);
|
|
245
|
-
break;
|
|
246
|
-
default:
|
|
247
|
-
console.log(`Unknown mindmap subcommand: ${subcommand}`);
|
|
248
|
-
process.exit(1);
|
|
249
|
-
}
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const engine = new engine_1.MemoryEngine();
|
|
253
|
-
if (resolvedCommand === 'summarize-dirty') {
|
|
254
|
-
engine.summarizeDirty();
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (!agentId) {
|
|
258
|
-
console.log('Error: agent_id is required');
|
|
259
|
-
process.exit(1);
|
|
260
|
-
}
|
|
261
|
-
switch (resolvedCommand) {
|
|
262
|
-
case 'save': {
|
|
263
|
-
const summary = rest[0];
|
|
264
|
-
if (!summary) {
|
|
265
|
-
console.log('Error: summary is required');
|
|
266
|
-
process.exit(1);
|
|
267
|
-
}
|
|
268
|
-
let category;
|
|
269
|
-
if (rest[1] && types_1.CATEGORIES.includes(rest[1])) {
|
|
270
|
-
category = rest[1];
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
category = 'general';
|
|
274
|
-
if (rest[1] && !options.tags) {
|
|
275
|
-
options.tags = rest[1];
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (rest[2] && !options.body) {
|
|
279
|
-
options.body = rest[2];
|
|
280
|
-
}
|
|
281
|
-
if (!options.body && !process.stdin.isTTY) {
|
|
282
|
-
const stdinBody = await Promise.race([
|
|
283
|
-
readStdin(),
|
|
284
|
-
new Promise((resolve) => setTimeout(() => resolve(''), 100)),
|
|
285
|
-
]);
|
|
286
|
-
if (stdinBody) {
|
|
287
|
-
options.body = stdinBody;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
engine.save(agentId, summary, category, options);
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
case 'index':
|
|
294
|
-
engine.index(agentId, options);
|
|
295
|
-
break;
|
|
296
|
-
case 'list':
|
|
297
|
-
engine.list(agentId, options);
|
|
298
|
-
break;
|
|
299
|
-
case 'stats':
|
|
300
|
-
engine.stats(agentId);
|
|
301
|
-
break;
|
|
302
|
-
case 'tags':
|
|
303
|
-
if (rest[0]) {
|
|
304
|
-
engine.topic(agentId, rest[0]);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
engine.tags(agentId);
|
|
308
|
-
}
|
|
309
|
-
break;
|
|
310
|
-
case 'recent':
|
|
311
|
-
engine.recent(agentId, parseInt(rest[0] ?? '', 10) || 30);
|
|
312
|
-
break;
|
|
313
|
-
case 'find':
|
|
314
|
-
if (!rest[0]) {
|
|
315
|
-
console.log('Error: keyword is required');
|
|
316
|
-
process.exit(1);
|
|
317
|
-
}
|
|
318
|
-
engine.find(agentId, rest[0]);
|
|
319
|
-
break;
|
|
320
|
-
case 'get':
|
|
321
|
-
if (!rest[0]) {
|
|
322
|
-
console.log('Error: memory_id is required');
|
|
323
|
-
process.exit(1);
|
|
324
|
-
}
|
|
325
|
-
engine.get(agentId, rest[0]);
|
|
326
|
-
break;
|
|
327
|
-
case 'search':
|
|
328
|
-
if (!rest[0]) {
|
|
329
|
-
console.log('Error: query is required');
|
|
330
|
-
process.exit(1);
|
|
331
|
-
}
|
|
332
|
-
engine.search(agentId, rest.join(' '));
|
|
333
|
-
break;
|
|
334
|
-
case 'update':
|
|
335
|
-
if (!rest[0]) {
|
|
336
|
-
console.log('Error: memory_id is required');
|
|
337
|
-
process.exit(1);
|
|
338
|
-
}
|
|
339
|
-
engine.update(agentId, rest[0], options);
|
|
340
|
-
break;
|
|
341
|
-
case 'delete':
|
|
342
|
-
if (!rest[0]) {
|
|
343
|
-
console.log('Error: memory_id is required');
|
|
344
|
-
process.exit(1);
|
|
345
|
-
}
|
|
346
|
-
engine.delete(agentId, rest[0], options);
|
|
347
|
-
break;
|
|
348
|
-
case 'merge':
|
|
349
|
-
if (!rest[0] || !rest[1]) {
|
|
350
|
-
console.log('Error: two memory_ids are required');
|
|
351
|
-
console.log('Usage: node cli.ts merge <agent_id> <id1> <id2> [--summary="병합 요약"]');
|
|
352
|
-
process.exit(1);
|
|
353
|
-
}
|
|
354
|
-
engine.merge(agentId, rest[0], rest[1], options);
|
|
355
|
-
break;
|
|
356
|
-
case 'summarize':
|
|
357
|
-
engine.summarize(agentId, options);
|
|
358
|
-
break;
|
|
359
|
-
default:
|
|
360
|
-
console.log(`Unknown command: ${command}`);
|
|
361
|
-
process.exit(1);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if (require.main === module) {
|
|
365
|
-
loadTracer().then(tracer => {
|
|
366
|
-
const opts = tracer ? { skillVersion: tracer.getOwnSkillVersion(__dirname) } : {};
|
|
367
|
-
return tracer ? tracer.run('crewx/memory', () => main(), opts) : main();
|
|
368
|
-
}).catch((e) => {
|
|
369
|
-
console.error(e.message);
|
|
370
|
-
process.exit(1);
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
//# sourceMappingURL=cli.js.map
|
|
36
|
+
`)}const j={read:"get",rm:"delete",ls:"recent"};const A=new Set(["help","force","verbose","full","important","no-important","json","all","version"]);function M(s){const r={positional:[],options:{}};for(let i=0;i<s.length;i++){const e=s[i];if(e==="-h"){r.options["help"]=true}else if(e.startsWith("--")){const t=e.indexOf("=");if(t!==-1){const n=e.slice(2,t);const o=e.slice(t+1);r.options[n]=o}else{const n=e.slice(2);if(!A.has(n)){const o=s[i+1];if(o!==void 0&&!o.startsWith("--")&&o!=="-h"){r.options[n]=o;i++}else{r.options[n]=true}}else{r.options[n]=true}}}else{r.positional.push(e)}}return r}async function b(s){const r=s??process.argv.slice(2);const{positional:i,options:e}=M(r);const[t,n,...o]=i;if(e.version){console.log(_);return}if(e.help){h();return}if(t==="usage"){O();return}if(t==="help"){h();return}if(!t){h();return}const g=j[t]??t;if(g==="mindmap"){const l=process.env["MEMORY_DATA_DIR"]??f.resolve(process.cwd(),"memory");const m=new S.MindmapEngine(l);const u=n;const c=o[0];const d=o.slice(1);if(!u){console.log("Usage: npx memory mindmap <subcommand> [agent_id] [args]");console.log("");console.log("Subcommands:");console.log(" build <agent_id> - Build graph");console.log(" show <agent_id> [--period=stm|mtm|ltm] [--format=mermaid|text] - Graph summary");console.log(" related <agent_id> <memory_id> - View related memories");console.log(" add <agent_id> <from_id> <to_id> [type] - Add manual relation");console.log(" remove <agent_id> <from_id> <to_id> - Remove relation");console.log(" html - Generate shared HTML");console.log(" open [agent_id] - Open in browser");process.exit(1)}switch(u){case"build":if(!c){console.log("Error: agent_id is required");process.exit(1)}m.build(c,e);break;case"show":if(!c){console.log("Error: agent_id is required");process.exit(1)}m.show(c,{period:e.period,format:e.format});break;case"related":if(!c||!d?.[0]){console.log("Error: agent_id and memory_id are required");process.exit(1)}m.related(c,d[0]);break;case"add":if(!c||!d?.[0]||!d?.[1]){console.log("Error: agent_id, from_id and to_id are required");process.exit(1)}m.add(c,d[0],d[1],d[2]);break;case"remove":if(!c||!d?.[0]||!d?.[1]){console.log("Error: agent_id, from_id and to_id are required");process.exit(1)}m.remove(c,d[0],d[1]);break;case"html":m.html();break;case"open":m.open(c);break;default:console.log(`Unknown mindmap subcommand: ${u}`);process.exit(1)}return}const a=new k.MemoryEngine;if(g==="summarize-dirty"){a.summarizeDirty();return}if(!n){console.log("Error: agent_id is required");process.exit(1)}switch(g){case"save":{const l=o[0];if(!l){console.log("Error: summary is required");process.exit(1)}let m;if(o[1]&&x.CATEGORIES.includes(o[1])){m=o[1]}else{m="general";if(o[1]&&!e.tags){e.tags=o[1]}}if(o[2]&&!e.body){e.body=o[2]}if(!e.body&&!process.stdin.isTTY){const u=q();let c;try{c=await Promise.race([u.body,new Promise(d=>setTimeout(()=>d(""),100))])}finally{u.release()}if(c){e.body=c}}a.save(n,l,m,e);break}case"index":a.index(n,e);break;case"list":a.list(n,e);break;case"stats":a.stats(n);break;case"tags":if(o[0]){a.topic(n,o[0])}else{a.tags(n)}break;case"recent":a.recent(n,parseInt(o[0]??"",10)||30);break;case"find":if(!o[0]){console.log("Error: keyword is required");process.exit(1)}a.find(n,o[0]);break;case"get":if(!o[0]){console.log("Error: memory_id is required");process.exit(1)}a.get(n,o[0]);break;case"search":if(!o[0]){console.log("Error: query is required");process.exit(1)}a.search(n,o.join(" "));break;case"update":if(!o[0]){console.log("Error: memory_id is required");process.exit(1)}a.update(n,o[0],e);break;case"delete":if(!o[0]){console.log("Error: memory_id is required");process.exit(1)}a.delete(n,o[0],e);break;case"merge":if(!o[0]||!o[1]){console.log("Error: two memory_ids are required");console.log('Usage: node cli.ts merge <agent_id> <id1> <id2> [--summary="merge summary"]');process.exit(1)}a.merge(n,o[0],o[1],e);break;case"summarize":a.summarize(n,e);break;default:console.log(`Unknown command: ${t}`);process.exit(1)}}if(require.main===module){E().then(s=>{const r=s?{skillVersion:s.getOwnSkillVersion(__dirname)}:{};return s?s.run("crewx/memory",()=>b(),r):b()}).catch(s=>{console.error(s.message);process.exit(1)})}
|
package/dist/src/engine.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare const SUMMARIZER_FAILURE_THRESHOLD = 3;
|
|
2
|
+
export declare const SUMMARIZE_LOCK_STALE_MS: number;
|
|
1
3
|
import { MemoryEntry, SaveOptions, IndexOptions, ListOptions, UpdateOptions, DeleteOptions, MergeOptions, SummarizeOptions, SummaryResult, MemoryEngineConfig } from './types';
|
|
2
4
|
export declare function getMemoryConfig(): Record<string, unknown>;
|
|
3
5
|
export declare class MemoryEngine {
|
|
@@ -9,11 +11,18 @@ export declare class MemoryEngine {
|
|
|
9
11
|
private readonly searcherAgent;
|
|
10
12
|
private readonly summarizerTimeout;
|
|
11
13
|
private readonly searcherTimeout;
|
|
14
|
+
private readonly searchIndexCache;
|
|
12
15
|
constructor(config?: MemoryEngineConfig);
|
|
13
16
|
private getAgentDir;
|
|
14
17
|
private getEntriesDir;
|
|
18
|
+
private getEntryFilesFingerprint;
|
|
19
|
+
private buildSearchIndex;
|
|
20
|
+
private getSearchIndex;
|
|
21
|
+
private invalidateSearchIndex;
|
|
22
|
+
private createFindActionContext;
|
|
15
23
|
private getSummaryPath;
|
|
16
24
|
private getDirtySummaryPath;
|
|
25
|
+
private getSummarizeLockPath;
|
|
17
26
|
private ensureDir;
|
|
18
27
|
private generateId;
|
|
19
28
|
private getToday;
|
|
@@ -21,6 +30,12 @@ export declare class MemoryEngine {
|
|
|
21
30
|
private getPrimaryTag;
|
|
22
31
|
private toEntryTimestamp;
|
|
23
32
|
private markSummaryDirty;
|
|
33
|
+
private getSummarizerHealthPath;
|
|
34
|
+
private readSummarizerHealth;
|
|
35
|
+
private writeSummarizerHealth;
|
|
36
|
+
private recordSummarizerFailure;
|
|
37
|
+
private recordSummarizerSuccess;
|
|
38
|
+
private notifySummarizerDegraded;
|
|
24
39
|
loadAllEntries(agentId: string): MemoryEntry[];
|
|
25
40
|
private findEntryById;
|
|
26
41
|
save(agentId: string, summary: string, category?: string, options?: SaveOptions): void;
|
|
@@ -28,6 +43,12 @@ export declare class MemoryEngine {
|
|
|
28
43
|
private generateIndexContent;
|
|
29
44
|
topic(agentId: string, topicName: string): void;
|
|
30
45
|
recent(agentId: string, days?: number): void;
|
|
46
|
+
getRecentEntries(agentId: string, days?: number, opts?: {
|
|
47
|
+
includeBody?: boolean;
|
|
48
|
+
}): MemoryEntry[];
|
|
49
|
+
private resolveRecentDate;
|
|
50
|
+
private toDateString;
|
|
51
|
+
private readEntryBody;
|
|
31
52
|
find(agentId: string, keyword: string): void;
|
|
32
53
|
list(agentId: string, options?: ListOptions): void;
|
|
33
54
|
stats(agentId: string): void;
|
|
@@ -40,9 +61,12 @@ export declare class MemoryEngine {
|
|
|
40
61
|
private callSummarizer;
|
|
41
62
|
generateSummary(agentId: string, options?: SummarizeOptions): SummaryResult;
|
|
42
63
|
summarize(agentId: string, options?: SummarizeOptions): void;
|
|
64
|
+
private isSummarizeLockStale;
|
|
65
|
+
private acquireSummarizeLock;
|
|
66
|
+
private releaseSummarizeLock;
|
|
43
67
|
summarizeDirty(): void;
|
|
44
68
|
search(agentId: string, query: string): void;
|
|
45
69
|
}
|
|
46
70
|
export declare function createMemoryEngine(config?: MemoryEngineConfig): MemoryEngine;
|
|
47
71
|
export { CATEGORIES, MemoryCategory } from './types';
|
|
48
|
-
|
|
72
|
+
|