-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory-cli.js
More file actions
100 lines (85 loc) · 3.12 KB
/
Copy pathmemory-cli.js
File metadata and controls
100 lines (85 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
/**
* XM-EVO Graph Memory CLI
* 图记忆系统命令行工具
*/
const { GraphMemory } = require('./src/core/graph-memory');
const { MemorySync } = require('./src/core/memory-sync');
const path = require('path');
const DB_PATH = path.join(__dirname, 'data/memory.db');
async function main() {
const args = process.argv.slice(2);
const command = args[0];
const gm = new GraphMemory(DB_PATH);
try {
switch (command) {
case 'sync':
console.log('🔄 同步记忆文件到图数据库...\n');
const sync = new MemorySync(gm);
const stats = await sync.fullSync();
console.log('\n📊 同步结果:', stats);
break;
case 'search':
const query = args.slice(1).join(' ');
if (!query) {
console.log('用法: node memory-cli.js search <查询内容>');
process.exit(1);
}
console.log(`🔍 搜索: "${query}"\n`);
const results = await gm.search(query, 10);
console.log('📋 搜索结果:');
results.forEach((r, i) => {
console.log(`\n${i + 1}. [${r.node.type}] ${r.node.id}`);
console.log(` 相关度: ${(r.relevance * 100).toFixed(1)}%`);
console.log(` 代价: ${r.cost.toFixed(3)}`);
console.log(` 内容: ${r.node.content.substring(0, 100)}...`);
});
break;
case 'stats':
console.log('📈 图记忆统计:\n');
console.log(gm.getStats());
break;
case 'add':
const [id, type, content, layer] = args.slice(1);
if (!id || !type || !content) {
console.log('用法: node memory-cli.js add <id> <type> <content> [layer]');
process.exit(1);
}
gm.addNode(id, type, content, { layer: parseInt(layer) || 4 });
console.log(`✅ 添加节点: ${id}`);
break;
case 'link':
const [from, to, relation, weight] = args.slice(1);
if (!from || !to || !relation) {
console.log('用法: node memory-cli.js link <from> <to> <relation> [weight]');
process.exit(1);
}
gm.addEdge(from, to, relation, { weight: parseFloat(weight) || 1.0 });
console.log(`✅ 创建边: ${from} --[${relation}]--> ${to}`);
break;
case 'query':
const sql = args.slice(1).join(' ');
const rows = gm.db.prepare(sql).all();
console.log(rows);
break;
default:
console.log(`
🧠 XM-EVO Graph Memory CLI
用法:
node memory-cli.js sync 同步 Markdown 文件到图数据库
node memory-cli.js search <query> 图检索(Bundle Search)
node memory-cli.js stats 显示统计信息
node memory-cli.js add <id> <type> <content> [layer] 添加节点
node memory-cli.js link <from> <to> <relation> [weight] 创建边
node memory-cli.js query <sql> 执行 SQL 查询
示例:
node memory-cli.js sync
node memory-cli.js search "抖音项目"
node memory-cli.js search "Playwright 技巧"
`);
}
} finally {
gm.close();
}
}
main().catch(console.error);