natureco-cli 2.20.2 → 2.21.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.
- package/package.json +1 -1
- package/src/commands/code.js +80 -5
package/package.json
CHANGED
package/src/commands/code.js
CHANGED
|
@@ -141,6 +141,48 @@ function buildIndexPrompt(index) {
|
|
|
141
141
|
return lines.join('\n');
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
// ── Proje hafızası ────────────────────────────────────────────────────────────
|
|
145
|
+
function getProjectMemoryPath() {
|
|
146
|
+
return path.join(process.cwd(), '.natureco', 'project.md');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function loadProjectMemory() {
|
|
150
|
+
try {
|
|
151
|
+
const p = getProjectMemoryPath();
|
|
152
|
+
if (fs.existsSync(p)) return fs.readFileSync(p, 'utf8');
|
|
153
|
+
} catch {}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function generateSummary(messages, providerConfig) {
|
|
158
|
+
const recent = messages.filter(m => m.role !== 'system').slice(-12);
|
|
159
|
+
if (!recent.length) return 'Bu session boş geçti.';
|
|
160
|
+
const prompt = `Bu kod session'ını 3-5 madde halinde Türkçe özetle. Ne yapıldı, hangi dosyalar değiştirildi, hangi sorunlar çözüldü:\n${JSON.stringify(recent).slice(0, 3000)}`;
|
|
161
|
+
try {
|
|
162
|
+
const res = await fetch(`${providerConfig.url}/chat/completions`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'Authorization': `Bearer ${providerConfig.apiKey}`, 'Content-Type': 'application/json' },
|
|
165
|
+
body: JSON.stringify({ model: providerConfig.model, messages: [{ role: 'user', content: prompt }], max_tokens: 400, stream: false }),
|
|
166
|
+
});
|
|
167
|
+
const data = await res.json();
|
|
168
|
+
return data.choices?.[0]?.message?.content || 'Özet oluşturulamadı.';
|
|
169
|
+
} catch {
|
|
170
|
+
return 'Özet oluşturulamadı.';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function saveProjectMemory(messages, providerConfig) {
|
|
175
|
+
const sp = startSpinner('Proje hafızası güncelleniyor...');
|
|
176
|
+
const summary = await generateSummary(messages, providerConfig);
|
|
177
|
+
stopSpinner(sp, 'Proje hafızası güncellendi', true);
|
|
178
|
+
const memPath = getProjectMemoryPath();
|
|
179
|
+
const dir = path.dirname(memPath);
|
|
180
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
181
|
+
const existing = fs.existsSync(memPath) ? fs.readFileSync(memPath, 'utf8') : '# Proje Hafızası\n';
|
|
182
|
+
const entry = `\n## ${new Date().toLocaleDateString('tr-TR')} — ${new Date().toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' })}\n${summary}\n`;
|
|
183
|
+
fs.writeFileSync(memPath, existing + entry);
|
|
184
|
+
}
|
|
185
|
+
|
|
144
186
|
// ── Git helpers ───────────────────────────────────────────────────────────────
|
|
145
187
|
async function generateCommitMessage(diff, providerConfig) {
|
|
146
188
|
const body = {
|
|
@@ -378,6 +420,12 @@ ${indexPrompt}`;
|
|
|
378
420
|
if (agentsPrompt) systemPrompt += `\n\n## Project Instructions\n${agentsPrompt}`;
|
|
379
421
|
if (memoryPrompt) systemPrompt += '\n\n' + memoryPrompt;
|
|
380
422
|
|
|
423
|
+
// ── Proje hafızası ────────────────────────────────────────────────────────
|
|
424
|
+
const projectMemory = loadProjectMemory();
|
|
425
|
+
if (projectMemory) {
|
|
426
|
+
systemPrompt += `\n\n## Proje Geçmişi (.natureco/project.md)\n${projectMemory.slice(0, 2000)}`;
|
|
427
|
+
}
|
|
428
|
+
|
|
381
429
|
// Hedef dosya varsa context'e ekle
|
|
382
430
|
if (targetFile) {
|
|
383
431
|
try {
|
|
@@ -428,6 +476,7 @@ ${indexPrompt}`;
|
|
|
428
476
|
console.log(centerText(chalk.gray(`🌿 ${projectIndex.gitBranch} · ${changes} değişiklik`)));
|
|
429
477
|
}
|
|
430
478
|
if (targetFile) console.log(centerText(chalk.gray(`📄 ${targetFile}`)));
|
|
479
|
+
if (projectMemory) console.log(centerText(chalk.gray(`📋 Proje hafızası yüklendi`)));
|
|
431
480
|
console.log(centerText(chalk.gray(`${shortModel} · /help · Ctrl+C çıkış`)));
|
|
432
481
|
console.log(sep());
|
|
433
482
|
console.log();
|
|
@@ -493,7 +542,8 @@ ${indexPrompt}`;
|
|
|
493
542
|
console.log(chalk.yellow('Code Agent Komutları:'));
|
|
494
543
|
[
|
|
495
544
|
['/clear', 'Ekranı temizle'],
|
|
496
|
-
['/summary', 'Session özetini göster'],
|
|
545
|
+
['/summary', 'Session özetini göster ve kaydet'],
|
|
546
|
+
['/memory', 'Proje hafızasını göster'],
|
|
497
547
|
['/done', 'Bitir ve özet göster'],
|
|
498
548
|
['/index', 'Projeyi yeniden indexle'],
|
|
499
549
|
['/run <cmd>','Komutu çalıştır, hata varsa düzelt'],
|
|
@@ -509,10 +559,25 @@ ${indexPrompt}`;
|
|
|
509
559
|
console.clear();
|
|
510
560
|
return;
|
|
511
561
|
case 'summary':
|
|
512
|
-
case 'done':
|
|
562
|
+
case 'done': {
|
|
563
|
+
const sum = await generateSummary(conversationMessages, providerConfig);
|
|
564
|
+
console.log(chalk.yellow('\n 📝 Session Özeti:'));
|
|
565
|
+
console.log(chalk.white(' ' + sum.split('\n').join('\n ')));
|
|
566
|
+
console.log();
|
|
513
567
|
showSummary();
|
|
514
568
|
if (cmd === 'done') process.exit(0);
|
|
515
569
|
return;
|
|
570
|
+
}
|
|
571
|
+
case 'memory': {
|
|
572
|
+
const mem = loadProjectMemory();
|
|
573
|
+
if (mem) {
|
|
574
|
+
console.log(chalk.yellow('\n 📋 Proje Hafızası:'));
|
|
575
|
+
console.log(chalk.gray(' ' + mem.slice(0, 1500).split('\n').join('\n ')));
|
|
576
|
+
} else {
|
|
577
|
+
console.log(chalk.gray('\n Henüz proje hafızası yok. /done ile kaydet.\n'));
|
|
578
|
+
}
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
516
581
|
case 'index': {
|
|
517
582
|
const sp = startSpinner('Proje yeniden indexleniyor...');
|
|
518
583
|
const newIndex = await indexProject(process.cwd());
|
|
@@ -664,10 +729,20 @@ ${indexPrompt}`;
|
|
|
664
729
|
// ── Input loop ───────────────────────────────────────────────────────────────
|
|
665
730
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
666
731
|
|
|
667
|
-
process.on('SIGINT', () => {
|
|
668
|
-
|
|
732
|
+
process.on('SIGINT', async () => {
|
|
733
|
+
console.log('\n');
|
|
734
|
+
if (rl) rl.pause();
|
|
735
|
+
if (conversationMessages.filter(m => m.role === 'user').length > 0) {
|
|
736
|
+
try {
|
|
737
|
+
const { save } = await inquirer.prompt([{
|
|
738
|
+
type: 'confirm', name: 'save',
|
|
739
|
+
message: chalk.yellow("Bu session'ı proje hafızasına kaydet?"),
|
|
740
|
+
default: true,
|
|
741
|
+
}]);
|
|
742
|
+
if (save) await saveProjectMemory(conversationMessages, providerConfig);
|
|
743
|
+
} catch {}
|
|
744
|
+
}
|
|
669
745
|
showSummary();
|
|
670
|
-
console.log(chalk.gray('👋 Goodbye!\n'));
|
|
671
746
|
process.exit(0);
|
|
672
747
|
});
|
|
673
748
|
|