natureco-cli 2.20.0 → 2.20.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 +69 -1
package/package.json
CHANGED
package/src/commands/code.js
CHANGED
|
@@ -141,7 +141,28 @@ function buildIndexPrompt(index) {
|
|
|
141
141
|
return lines.join('\n');
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
// ──
|
|
144
|
+
// ── Git helpers ───────────────────────────────────────────────────────────────
|
|
145
|
+
async function generateCommitMessage(diff, providerConfig) {
|
|
146
|
+
const body = {
|
|
147
|
+
model: providerConfig.model,
|
|
148
|
+
messages: [
|
|
149
|
+
{ role: 'system', content: 'Sen bir git commit mesajı üreticisin. Conventional Commits formatında (feat/fix/refactor/chore vb.) kısa ve açıklayıcı bir commit mesajı yaz. Sadece mesajı yaz, başka hiçbir şey yazma.' },
|
|
150
|
+
{ role: 'user', content: `Bu diff için commit mesajı üret:\n\n${diff}` },
|
|
151
|
+
],
|
|
152
|
+
temperature: 0.3,
|
|
153
|
+
max_tokens: 100,
|
|
154
|
+
stream: false,
|
|
155
|
+
};
|
|
156
|
+
const res = await fetch(`${providerConfig.url}/chat/completions`, {
|
|
157
|
+
method: 'POST',
|
|
158
|
+
headers: { 'Authorization': `Bearer ${providerConfig.apiKey}`, 'Content-Type': 'application/json' },
|
|
159
|
+
body: JSON.stringify(body),
|
|
160
|
+
});
|
|
161
|
+
const data = await res.json();
|
|
162
|
+
return (data.choices?.[0]?.message?.content || 'chore: update files').trim().replace(/^["']|["']$/g, '');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
145
166
|
async function streamMessage(providerConfig, messages, tools) {
|
|
146
167
|
const endpoint = `${providerConfig.url}/chat/completions`;
|
|
147
168
|
const body = {
|
|
@@ -245,6 +266,10 @@ async function runToolCall(toolCall, stats) {
|
|
|
245
266
|
stats.filesChanged++;
|
|
246
267
|
stats.changedFiles.push(toolCall.input.path || '?');
|
|
247
268
|
console.log(chalk.green(` ✓ ${toolCall.input.path} güncellendi`));
|
|
269
|
+
if (stats.changedFiles.length === 1) {
|
|
270
|
+
// İlk değişiklikte ipucu göster
|
|
271
|
+
console.log(chalk.gray(` 💡 git add . && /commit ile kaydet`));
|
|
272
|
+
}
|
|
248
273
|
}
|
|
249
274
|
if (toolCall.name === 'bash') stats.commandsRun++;
|
|
250
275
|
stats.toolCallCount++;
|
|
@@ -441,6 +466,8 @@ ${indexPrompt}`;
|
|
|
441
466
|
['/summary', 'Session özetini göster'],
|
|
442
467
|
['/done', 'Bitir ve özet göster'],
|
|
443
468
|
['/index', 'Projeyi yeniden indexle'],
|
|
469
|
+
['/git', 'Git durumu ve son commitler'],
|
|
470
|
+
['/commit', 'Staged değişiklikleri AI ile commit et'],
|
|
444
471
|
['/help', 'Bu yardım'],
|
|
445
472
|
].forEach(([c, d]) => console.log(' ' + chalk.cyan(c.padEnd(12)) + chalk.gray(d)));
|
|
446
473
|
console.log(chalk.gray(' Ctrl+C'.padEnd(14) + 'Çıkış'));
|
|
@@ -465,6 +492,47 @@ ${indexPrompt}`;
|
|
|
465
492
|
);
|
|
466
493
|
return;
|
|
467
494
|
}
|
|
495
|
+
case 'git': {
|
|
496
|
+
try {
|
|
497
|
+
const status = execSync('git status --short', { cwd: process.cwd(), stdio: 'pipe' }).toString().trim();
|
|
498
|
+
const log = execSync('git log --oneline -5', { cwd: process.cwd(), stdio: 'pipe' }).toString().trim();
|
|
499
|
+
console.log(chalk.yellow('\n Git Durumu:'));
|
|
500
|
+
console.log(status ? chalk.gray(' ' + status.split('\n').join('\n ')) : chalk.gray(' temiz'));
|
|
501
|
+
console.log(chalk.yellow('\n Son Commitler:'));
|
|
502
|
+
console.log(chalk.gray(' ' + log.split('\n').join('\n ')));
|
|
503
|
+
console.log();
|
|
504
|
+
} catch (e) {
|
|
505
|
+
console.log(chalk.red(' Git bulunamadı veya bu dizin bir git repo değil.\n'));
|
|
506
|
+
}
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
case 'commit': {
|
|
510
|
+
try {
|
|
511
|
+
const diff = execSync('git diff --staged', { cwd: process.cwd(), stdio: 'pipe' }).toString();
|
|
512
|
+
if (!diff.trim()) {
|
|
513
|
+
console.log(chalk.red('\n Staged değişiklik yok.'));
|
|
514
|
+
console.log(chalk.gray(' Önce: git add .\n'));
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const sp = startSpinner('Commit mesajı üretiliyor...');
|
|
518
|
+
const commitMsg = await generateCommitMessage(diff.slice(0, 2000), providerConfig);
|
|
519
|
+
stopSpinner(sp, 'Commit mesajı hazır', true);
|
|
520
|
+
console.log(chalk.cyan(`\n Önerilen: ${chalk.white(commitMsg)}\n`));
|
|
521
|
+
const { ok } = await inquirer.prompt([{
|
|
522
|
+
type: 'confirm', name: 'ok',
|
|
523
|
+
message: ' Commit edilsin mi?', default: true,
|
|
524
|
+
}]);
|
|
525
|
+
if (ok) {
|
|
526
|
+
execSync(`git commit -m "${commitMsg.replace(/"/g, '\\"')}"`, { cwd: process.cwd(), stdio: 'pipe' });
|
|
527
|
+
console.log(chalk.green(' ✓ Commit yapıldı!\n'));
|
|
528
|
+
} else {
|
|
529
|
+
console.log(chalk.gray(' İptal edildi.\n'));
|
|
530
|
+
}
|
|
531
|
+
} catch (e) {
|
|
532
|
+
console.log(chalk.red(` Git hatası: ${e.message}\n`));
|
|
533
|
+
}
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
468
536
|
default:
|
|
469
537
|
console.log(chalk.red(`Bilinmeyen komut: /${cmd}\n`));
|
|
470
538
|
return;
|