natureco-cli 5.6.15 → 5.6.17
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/bin/natureco.js +1085 -1084
- package/package.json +1 -1
- package/src/commands/memory-cmd.js +406 -338
- package/src/commands/reset.js +23 -12
- package/src/utils/dangerous.js +110 -0
- package/src/utils/memory-store.js +185 -0
|
@@ -1,338 +1,406 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (action === '
|
|
15
|
-
if (action === '
|
|
16
|
-
if (action === '
|
|
17
|
-
if (action === '
|
|
18
|
-
if (action === '
|
|
19
|
-
if (action === '
|
|
20
|
-
if (action === '
|
|
21
|
-
if (action === '
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (action === 'wiki
|
|
25
|
-
if (action === 'wiki-
|
|
26
|
-
if (action === 'wiki-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(chalk.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(
|
|
40
|
-
console.log(
|
|
41
|
-
console.log(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
console.log(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
console.log(bar + '
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.log(bar + ' ' + chalk.gray('
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
console.log(
|
|
88
|
-
console.log(
|
|
89
|
-
console.log(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
console.log(chalk.
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.log(chalk.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
console.log(
|
|
161
|
-
console.log(chalk.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (mem.
|
|
165
|
-
if (mem.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
console.log(chalk.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
console.log(chalk.
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
const
|
|
271
|
-
if (!
|
|
272
|
-
|
|
273
|
-
console.log(chalk.
|
|
274
|
-
console.log(chalk.
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const
|
|
292
|
-
console.log(chalk.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
console.log(chalk.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const memoryStore = require('../utils/memory-store');
|
|
6
|
+
const { loadMemory, saveMemory, clearMemory } = require('../utils/memory');
|
|
7
|
+
const { getConfig } = require('../utils/config');
|
|
8
|
+
|
|
9
|
+
const MEMORY_DIR = path.join(os.homedir(), '.natureco', 'memory');
|
|
10
|
+
|
|
11
|
+
async function memoryCmd(args) {
|
|
12
|
+
const [action, ...params] = (args || []);
|
|
13
|
+
|
|
14
|
+
if (!action || action === 'status') return statusMemory();
|
|
15
|
+
if (action === 'list') return listMemory();
|
|
16
|
+
if (action === 'search') return searchMemory(params.join(' '));
|
|
17
|
+
if (action === 'show') return showMemory(params[0]);
|
|
18
|
+
if (action === 'clear') return clearMemoryCmd(params[0]);
|
|
19
|
+
if (action === 'index') return indexMemory();
|
|
20
|
+
if (action === 'export') return exportMemoryCmd(params[0], params[1]);
|
|
21
|
+
if (action === 'import') return importMemoryCmd(params[0], params[1]);
|
|
22
|
+
if (action === 'semantic') return semanticSearchCmd(params.join(' '));
|
|
23
|
+
// Wiki pages
|
|
24
|
+
if (action === 'wiki') return wikiCmd(params[0], params.slice(1));
|
|
25
|
+
if (action === 'wiki-create') return wikiCreateCmd(params[0], params.slice(1).join(' '));
|
|
26
|
+
if (action === 'wiki-list') return wikiListCmd();
|
|
27
|
+
if (action === 'wiki-search') return wikiSearchCmd(params.join(' '));
|
|
28
|
+
|
|
29
|
+
console.log(chalk.red(`\n ❌ Bilinmeyen komut: ${action}\n`));
|
|
30
|
+
console.log(chalk.gray(' Kullanım: natureco memory [status|list|search|show|clear|index|export|import|semantic|wiki|wiki-create|wiki-list|wiki-search]\n'));
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function statusMemory() {
|
|
35
|
+
const config = getConfig();
|
|
36
|
+
const w = process.stdout.columns || 120;
|
|
37
|
+
const line = chalk.gray('─'.repeat(w));
|
|
38
|
+
|
|
39
|
+
console.log('');
|
|
40
|
+
console.log(line);
|
|
41
|
+
console.log(chalk.bold.cyan(' Hafıza Durumu'));
|
|
42
|
+
console.log(line);
|
|
43
|
+
|
|
44
|
+
if (!fs.existsSync(MEMORY_DIR)) {
|
|
45
|
+
console.log(chalk.gray('\n Hafıza dizini bulunamadı.\n'));
|
|
46
|
+
console.log(line);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const files = fs.readdirSync(MEMORY_DIR).filter(f => f.endsWith('.json'));
|
|
51
|
+
|
|
52
|
+
if (files.length === 0) {
|
|
53
|
+
console.log(chalk.gray('\n Kayıtlı hafıza yok.\n'));
|
|
54
|
+
console.log(line);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let totalFacts = 0;
|
|
59
|
+
const activeBotName = config.botName || '';
|
|
60
|
+
|
|
61
|
+
console.log('');
|
|
62
|
+
files.forEach(file => {
|
|
63
|
+
const botId = file.replace('.json', '');
|
|
64
|
+
try {
|
|
65
|
+
const mem = loadMemory(botId);
|
|
66
|
+
const factCount = (mem.facts || []).length;
|
|
67
|
+
const prefCount = (mem.preferences || []).length;
|
|
68
|
+
totalFacts += factCount;
|
|
69
|
+
const isActive = activeBotName && (mem.botName === activeBotName);
|
|
70
|
+
const bar = isActive ? chalk.cyan('▌') : chalk.gray('▌');
|
|
71
|
+
|
|
72
|
+
console.log(bar + ' ' + chalk.bold.white(mem.botName || botId) + (isActive ? chalk.cyan(' ← aktif') : ''));
|
|
73
|
+
console.log(bar + ' ' + chalk.gray('Kullanıcı : ') + chalk.white(mem.name || '—'));
|
|
74
|
+
if (mem.nickname) {
|
|
75
|
+
console.log(bar + ' ' + chalk.gray('Lakap : ') + chalk.white(mem.nickname));
|
|
76
|
+
}
|
|
77
|
+
console.log(bar + ' ' + chalk.gray('Bilgi : ') + chalk.white(`${factCount} kayıt`));
|
|
78
|
+
console.log(bar + ' ' + chalk.gray('Tercihler : ') + chalk.white(`${prefCount} kayıt`));
|
|
79
|
+
if (mem.lastSeen) {
|
|
80
|
+
const d = new Date(mem.lastSeen);
|
|
81
|
+
console.log(bar + ' ' + chalk.gray('Son görüş : ') + chalk.white(d.toLocaleDateString('tr-TR')));
|
|
82
|
+
}
|
|
83
|
+
console.log('');
|
|
84
|
+
} catch {}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
console.log(line);
|
|
88
|
+
console.log(chalk.gray(` ${files.length} bot · ${totalFacts} toplam bilgi · natureco memory search <sorgu>`));
|
|
89
|
+
console.log(line);
|
|
90
|
+
console.log('');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function listMemory() {
|
|
94
|
+
if (!fs.existsSync(MEMORY_DIR)) {
|
|
95
|
+
console.log(chalk.gray('\n Hafıza dizini bulunamadı.\n'));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const files = fs.readdirSync(MEMORY_DIR).filter(f => f.endsWith('.json'));
|
|
100
|
+
console.log(chalk.cyan.bold(`\n Hafıza Dosyaları (${files.length})\n`));
|
|
101
|
+
files.forEach(f => {
|
|
102
|
+
const botId = f.replace('.json', '');
|
|
103
|
+
const mem = loadMemory(botId);
|
|
104
|
+
console.log(chalk.white(` ${f}`));
|
|
105
|
+
console.log(chalk.gray(` Bot: ${mem.botName || botId} · ${(mem.facts || []).length} bilgi`));
|
|
106
|
+
});
|
|
107
|
+
console.log('');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function searchMemory(query) {
|
|
111
|
+
if (!query) {
|
|
112
|
+
console.log(chalk.red('\n ❌ Arama sorgusu gerekli\n'));
|
|
113
|
+
console.log(chalk.gray(' Kullanım: natureco memory search <sorgu>\n'));
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!fs.existsSync(MEMORY_DIR)) {
|
|
118
|
+
console.log(chalk.gray('\n Hafıza dizini bulunamadı.\n'));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const files = fs.readdirSync(MEMORY_DIR).filter(f => f.endsWith('.json'));
|
|
123
|
+
const results = [];
|
|
124
|
+
|
|
125
|
+
files.forEach(file => {
|
|
126
|
+
const botId = file.replace('.json', '');
|
|
127
|
+
const mem = loadMemory(botId);
|
|
128
|
+
const q = query.toLowerCase();
|
|
129
|
+
|
|
130
|
+
if (mem.name?.toLowerCase().includes(q)) {
|
|
131
|
+
results.push({ bot: mem.botName || botId, field: 'İsim', value: mem.name });
|
|
132
|
+
}
|
|
133
|
+
if (mem.nickname?.toLowerCase().includes(q)) {
|
|
134
|
+
results.push({ bot: mem.botName || botId, field: 'Lakap', value: mem.nickname });
|
|
135
|
+
}
|
|
136
|
+
(mem.facts || []).forEach(f => {
|
|
137
|
+
const val = typeof f === 'string' ? f : f.value;
|
|
138
|
+
if (val?.toLowerCase().includes(q)) {
|
|
139
|
+
results.push({ bot: mem.botName || botId, field: 'Bilgi', value: val });
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
console.log(chalk.cyan.bold(`\n "${query}" için ${results.length} sonuç\n`));
|
|
145
|
+
if (results.length === 0) {
|
|
146
|
+
console.log(chalk.gray(' Sonuç bulunamadı.\n'));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
results.forEach(r => {
|
|
150
|
+
console.log(chalk.white(` [${r.bot}] `) + chalk.gray(`${r.field}: `) + chalk.white(r.value));
|
|
151
|
+
});
|
|
152
|
+
console.log('');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function showMemory(botId) {
|
|
156
|
+
const config = getConfig();
|
|
157
|
+
const id = botId || 'universal-provider';
|
|
158
|
+
const mem = loadMemory(id);
|
|
159
|
+
|
|
160
|
+
console.log('');
|
|
161
|
+
console.log(chalk.gray(' ' + '─'.repeat(48)));
|
|
162
|
+
console.log(chalk.cyan.bold(`\n Hafıza: ${mem.botName || id}\n`));
|
|
163
|
+
|
|
164
|
+
if (mem.name) console.log(chalk.gray(' İsim : ') + chalk.white(mem.name));
|
|
165
|
+
if (mem.nickname) console.log(chalk.gray(' Lakap : ') + chalk.white(mem.nickname));
|
|
166
|
+
if (mem.botName) console.log(chalk.gray(' Bot adı : ') + chalk.cyan(mem.botName));
|
|
167
|
+
|
|
168
|
+
const facts = mem.facts || [];
|
|
169
|
+
if (facts.length > 0) {
|
|
170
|
+
console.log(chalk.gray('\n Bilgiler:\n'));
|
|
171
|
+
facts.forEach((f, i) => {
|
|
172
|
+
const val = typeof f === 'string' ? f : f.value;
|
|
173
|
+
const score = typeof f === 'object' ? f.score : 5;
|
|
174
|
+
console.log(chalk.gray(` ${(i + 1).toString().padStart(2)}. `) + chalk.white(val) + chalk.gray(` (${score})`));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
console.log('');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function clearMemoryCmd(botId) {
|
|
181
|
+
const id = botId || 'universal-provider';
|
|
182
|
+
clearMemory(id);
|
|
183
|
+
console.log(chalk.green(`\n ✓ Hafıza temizlendi: ${id}\n`));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function indexMemory() {
|
|
187
|
+
if (!fs.existsSync(MEMORY_DIR)) {
|
|
188
|
+
console.log(chalk.gray('\n Hafıza dizini bulunamadı.\n'));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const files = fs.readdirSync(MEMORY_DIR).filter(f => f.endsWith('.json'));
|
|
193
|
+
let indexed = 0;
|
|
194
|
+
|
|
195
|
+
files.forEach(file => {
|
|
196
|
+
const botId = file.replace('.json', '');
|
|
197
|
+
try {
|
|
198
|
+
const mem = loadMemory(botId);
|
|
199
|
+
// Bozuk fact'leri temizle
|
|
200
|
+
if (Array.isArray(mem.facts)) {
|
|
201
|
+
mem.facts = mem.facts.filter(f => {
|
|
202
|
+
const val = typeof f === 'string' ? f : f?.value;
|
|
203
|
+
return val && typeof val === 'string' && val.length > 0;
|
|
204
|
+
});
|
|
205
|
+
saveMemory(botId, mem);
|
|
206
|
+
indexed++;
|
|
207
|
+
}
|
|
208
|
+
} catch {}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
console.log(chalk.green(`\n ✓ ${indexed} hafıza dosyası yeniden indexlendi\n`));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ── Export Memory ──────────────────────────────────────────────────────────────
|
|
215
|
+
function exportMemoryCmd(botId, outputFile) {
|
|
216
|
+
const id = botId || 'universal-provider';
|
|
217
|
+
const mem = memoryStore.loadMemory(id);
|
|
218
|
+
const filePath = outputFile || path.join(process.cwd(), `memory-${id}.json`);
|
|
219
|
+
fs.writeFileSync(filePath, JSON.stringify(mem, null, 2));
|
|
220
|
+
console.log(chalk.green(`\n ✓ Hafıza dışa aktarıldı: ${filePath}\n`));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ── Import Memory ──────────────────────────────────────────────────────────────
|
|
224
|
+
function importMemoryCmd(botId, sourceFile) {
|
|
225
|
+
if (!sourceFile) {
|
|
226
|
+
console.log(chalk.red('\n ❌ Kaynak dosya gerekli\n'));
|
|
227
|
+
console.log(chalk.gray(' Kullanım: natureco memory import <botId> <dosya.json>\n'));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const resolvedPath = path.resolve(sourceFile.replace(/^~/, os.homedir()));
|
|
231
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
232
|
+
console.log(chalk.red(`\n ❌ Dosya bulunamadı: ${resolvedPath}\n`));
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const data = JSON.parse(fs.readFileSync(resolvedPath, 'utf-8'));
|
|
237
|
+
// v5.6.16: memoryStore.saveMemory kullan
|
|
238
|
+
memoryStore.saveMemory(botId || 'universal-provider', data);
|
|
239
|
+
console.log(chalk.green(`\n ✓ Hafıza içe aktarıldı: ${id}\n`));
|
|
240
|
+
} catch (err) {
|
|
241
|
+
console.log(chalk.red(`\n ❌ Hata: ${err.message}\n`));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ── Semantic Search ────────────────────────────────────────────────────────────
|
|
246
|
+
function semanticSearchCmd(query) {
|
|
247
|
+
if (!query) {
|
|
248
|
+
console.log(chalk.red('\n ❌ Arama sorgusu gerekli\n'));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const results = semanticSearchMemory(query, 10);
|
|
252
|
+
console.log(chalk.cyan.bold(`\n Semantic: "${query}" → ${results.length} sonuç\n`));
|
|
253
|
+
if (results.length === 0) {
|
|
254
|
+
console.log(chalk.gray(' Sonuç bulunamadı.\n'));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
results.forEach((r, i) => {
|
|
258
|
+
const pct = Math.round(r.score * 100);
|
|
259
|
+
const bar = chalk.green('█'.repeat(Math.floor(pct / 10))) + chalk.gray('░'.repeat(10 - Math.floor(pct / 10)));
|
|
260
|
+
console.log(` ${chalk.white(`${i + 1}.`)} ${bar} ${chalk.white(r.value.slice(0, 70))}`);
|
|
261
|
+
console.log(chalk.gray(` [${r.bot}] alaka: %${pct}`));
|
|
262
|
+
});
|
|
263
|
+
console.log('');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ── Wiki Commands ──────────────────────────────────────────────────────────────
|
|
267
|
+
function wikiCmd(action, params) {
|
|
268
|
+
if (!action || action === 'list') return wikiListCmd();
|
|
269
|
+
if (action === 'show') {
|
|
270
|
+
const slug = params?.[0];
|
|
271
|
+
if (!slug) { console.log(chalk.red('\n ❌ Sayfa adı gerekli\n')); return; }
|
|
272
|
+
const page = getWikiPage(slug);
|
|
273
|
+
if (!page) { console.log(chalk.yellow(`\n ⚠ Sayfa bulunamadı: ${slug}\n`)); return; }
|
|
274
|
+
console.log(chalk.cyan.bold(`\n Wiki: ${page.slug}\n`));
|
|
275
|
+
console.log(chalk.white(page.content));
|
|
276
|
+
console.log(chalk.gray(`\n Son güncelleme: ${page.updatedAt}\n`));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (action === 'create' || action === 'edit') {
|
|
280
|
+
const slug = params?.[0];
|
|
281
|
+
const content = params?.slice(1).join(' ');
|
|
282
|
+
if (!slug || !content) {
|
|
283
|
+
console.log(chalk.red('\n ❌ Kullanım: natureco memory wiki create <slug> <içerik>\n'));
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
saveWikiPage(slug, content);
|
|
287
|
+
console.log(chalk.green(`\n ✓ Wiki sayfası kaydedildi: ${slug}\n`));
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (action === 'search') {
|
|
291
|
+
const query = params?.join(' ');
|
|
292
|
+
if (!query) { console.log(chalk.red('\n ❌ Arama sorgusu gerekli\n')); return; }
|
|
293
|
+
const results = searchWikiPages(query);
|
|
294
|
+
console.log(chalk.cyan.bold(`\n Wiki: "${query}" → ${results.length} sonuç\n`));
|
|
295
|
+
if (results.length === 0) { console.log(chalk.gray(' Sonuç bulunamadı.\n')); return; }
|
|
296
|
+
results.forEach(p => {
|
|
297
|
+
console.log(` ${chalk.white(p.slug)} ${chalk.gray('—')} ${chalk.gray((p.content || '').slice(0, 60))}`);
|
|
298
|
+
});
|
|
299
|
+
console.log('');
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
console.log(chalk.red(`\n ❌ Bilinmeyen wiki aksiyonu: ${action}\n`));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function wikiCreateCmd(slug, content) {
|
|
306
|
+
if (!slug || !content) {
|
|
307
|
+
console.log(chalk.red('\n ❌ Kullanım: natureco memory wiki-create <slug> <içerik>\n'));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
saveWikiPage(slug, content);
|
|
311
|
+
console.log(chalk.green(`\n ✓ Wiki sayfası oluşturuldu: ${slug}\n`));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function wikiListCmd() {
|
|
315
|
+
const pages = listWikiPages();
|
|
316
|
+
console.log(chalk.cyan.bold(`\n Wiki Sayfaları (${pages.length})\n`));
|
|
317
|
+
if (pages.length === 0) {
|
|
318
|
+
console.log(chalk.gray(' Henüz sayfa yok.\n'));
|
|
319
|
+
console.log(chalk.gray(' Oluşturmak: ') + chalk.cyan('natureco memory wiki create <slug> <içerik>\n'));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
pages.forEach(p => {
|
|
323
|
+
const preview = (p.content || '').slice(0, 60).replace(/\n/g, ' ');
|
|
324
|
+
console.log(` ${chalk.white(p.slug)} ${chalk.gray('—')} ${chalk.gray(preview)}`);
|
|
325
|
+
console.log(chalk.gray(` ${p.updatedAt}\n`));
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function wikiSearchCmd(query) {
|
|
330
|
+
if (!query) { console.log(chalk.red('\n ❌ Arama sorgusu gerekli\n')); return; }
|
|
331
|
+
const results = searchWikiPages(query);
|
|
332
|
+
console.log(chalk.cyan.bold(`\n Wiki Ara: "${query}" → ${results.length} sonuç\n`));
|
|
333
|
+
if (results.length === 0) { console.log(chalk.gray(' Sonuç bulunamadı.\n')); return; }
|
|
334
|
+
results.forEach(p => {
|
|
335
|
+
console.log(` ${chalk.white(p.slug)}`);
|
|
336
|
+
console.log(chalk.gray(` ${(p.content || '').slice(0, 80)}\n`));
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ── Wiki Page Functions (v5.6.16 inline) ─────────────────────────────
|
|
341
|
+
function listWikiPages() {
|
|
342
|
+
const WIKI_DIR = path.join(os.homedir(), '.natureco', 'wiki');
|
|
343
|
+
if (!fs.existsSync(WIKI_DIR)) {
|
|
344
|
+
console.log(chalk.gray('\n Wiki bos.\n'));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const files = fs.readdirSync(WIKI_DIR).filter(f => f.endsWith('.md'));
|
|
348
|
+
console.log(chalk.cyan(`\n Wiki Sayfalari (${files.length}):\n`));
|
|
349
|
+
files.forEach(f => console.log(` ${chalk.white(f.replace('.md',''))}`));
|
|
350
|
+
console.log();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function getWikiPage(slug) {
|
|
354
|
+
if (!slug) return;
|
|
355
|
+
const WIKI_DIR = path.join(os.homedir(), '.natureco', 'wiki');
|
|
356
|
+
const filePath = path.join(WIKI_DIR, `${slug}.md`);
|
|
357
|
+
if (!fs.existsSync(filePath)) {
|
|
358
|
+
console.log(chalk.red(`\n ❌ Wiki sayfasi bulunamadi: ${slug}\n`));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
console.log(chalk.cyan(`\n ${slug}\n`));
|
|
362
|
+
console.log(chalk.gray(' ' + '─'.repeat(60)));
|
|
363
|
+
console.log(fs.readFileSync(filePath, 'utf-8'));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function saveWikiPage(slug, content) {
|
|
367
|
+
if (!slug) return;
|
|
368
|
+
const WIKI_DIR = path.join(os.homedir(), '.natureco', 'wiki');
|
|
369
|
+
if (!fs.existsSync(WIKI_DIR)) fs.mkdirSync(WIKI_DIR, { recursive: true });
|
|
370
|
+
const filePath = path.join(WIKI_DIR, `${slug}.md`);
|
|
371
|
+
fs.writeFileSync(filePath, content);
|
|
372
|
+
console.log(chalk.green(`\n ✓ Wiki sayfasi kaydedildi: ${slug}\n`));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function searchWikiPages(query) {
|
|
376
|
+
if (!query) return [];
|
|
377
|
+
const WIKI_DIR = path.join(os.homedir(), '.natureco', 'wiki');
|
|
378
|
+
if (!fs.existsSync(WIKI_DIR)) return [];
|
|
379
|
+
const lower = query.toLowerCase();
|
|
380
|
+
return fs.readdirSync(WIKI_DIR)
|
|
381
|
+
.filter(f => f.endsWith('.md'))
|
|
382
|
+
.map(f => ({
|
|
383
|
+
slug: f.replace('.md', ''),
|
|
384
|
+
content: fs.readFileSync(path.join(WIKI_DIR, f), 'utf-8'),
|
|
385
|
+
}))
|
|
386
|
+
.filter(p => p.content.toLowerCase().includes(lower));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// ── Semantic Search (v5.6.16 inline - basit keyword-based) ───────────
|
|
390
|
+
function semanticSearchMemory(query, botId) {
|
|
391
|
+
const id = botId || 'universal-provider';
|
|
392
|
+
const mem = memoryStore.loadMemory(id);
|
|
393
|
+
if (!query) return [];
|
|
394
|
+
const lower = query.toLowerCase();
|
|
395
|
+
const results = [];
|
|
396
|
+
// facts icinde ara
|
|
397
|
+
(mem.facts || []).forEach(f => {
|
|
398
|
+
const text = (typeof f === 'string' ? f : f.value) || '';
|
|
399
|
+
if (text.toLowerCase().includes(lower)) {
|
|
400
|
+
results.push({ type: 'fact', value: text, score: f.score || 5 });
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
return results;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
module.exports = memoryCmd;
|