natureco-cli 2.23.3 → 2.23.5

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.
@@ -1,183 +1,70 @@
1
- const chalk = require('chalk');
2
- const { listSessions, loadSession } = require('../utils/sessions');
3
- const { getApiKey, getConfig } = require('../utils/config');
4
- const { getBots } = require('../utils/api');
5
-
6
- async function sessions(action, ...args) {
7
- if (!action || action === 'list') return listSessionsCommand();
8
- if (action === 'show') {
9
- const sessionId = args[0];
10
- if (!sessionId) {
11
- console.log(chalk.red('\n ❌ Session ID gerekli\n'));
12
- console.log(chalk.gray(' Kullanım: natureco sessions show <id>\n'));
13
- process.exit(1);
14
- }
15
- return showSession(sessionId);
16
- }
17
- console.log(chalk.red(`\n ❌ Bilinmeyen komut: ${action}\n`));
18
- console.log(chalk.gray(' Kullanım: natureco sessions [list|show]\n'));
19
- process.exit(1);
20
- }
21
-
22
- async function listSessionsCommand() {
23
- const apiKey = getApiKey();
24
- const w = process.stdout.columns || 120;
25
- const line = chalk.gray('─'.repeat(w));
26
-
27
- if (!apiKey) {
28
- console.log(chalk.red('\n Giriş yapılmamış. natureco login\n'));
29
- process.exit(1);
30
- }
31
-
32
- let botList;
33
- try {
34
- botList = await getBots(apiKey);
35
- } catch (err) {
36
- console.log(chalk.red(`\n ❌ Hata: ${err.message}\n`));
37
- process.exit(1);
38
- }
39
-
40
- if (!botList?.bots?.length) {
41
- console.log(chalk.gray('\n Bot bulunamadı.\n'));
42
- return;
43
- }
44
-
45
- // Tüm session'ları topla
46
- const allSessions = [];
47
- botList.bots.forEach(bot => {
48
- const list = listSessions(bot.id);
49
- list.forEach(s => {
50
- allSessions.push({
51
- ...s,
52
- botName: bot.name,
53
- messageCount: (s.messages || []).length,
54
- lastMessage: s.messages?.slice(-1)[0]?.user || '',
55
- });
56
- });
57
- });
58
-
59
- // 0 mesajlıları filtrele
60
- const active = allSessions.filter(s => s.messageCount > 0);
61
-
62
- console.log('');
63
- console.log(line);
64
- const title = chalk.bold.cyan(' Oturumlar');
65
- const count = chalk.gray(`${active.length} aktif `);
66
- const pad = w - 12 - String(active.length).length - 8;
67
- console.log(title + ' '.repeat(Math.max(1, pad)) + count);
68
- console.log(line);
69
-
70
- if (active.length === 0) {
71
- console.log(chalk.gray('\n Henüz oturum yok.\n'));
72
- console.log(line);
73
- return;
74
- }
75
-
76
- // Grupla
77
- const now = Date.now();
78
- const todayStr = new Date().toDateString();
79
- const groups = { 'Bugün': [], 'Bu Hafta': [], 'Daha Önce': [] };
80
-
81
- active.forEach(s => {
82
- const d = new Date(s.createdAt);
83
- if (d.toDateString() === todayStr) groups['Bugün'].push(s);
84
- else if (now - d < 7 * 24 * 60 * 60 * 1000) groups['Bu Hafta'].push(s);
85
- else groups['Daha Önce'].push(s);
86
- });
87
-
88
- // Kolon genişlikleri
89
- const dateW = 17;
90
- const botW = 14;
91
- const previewW = Math.max(20, w - dateW - botW - 18 - 10);
92
-
93
- Object.entries(groups).forEach(([label, items]) => {
94
- if (!items.length) return;
95
-
96
- console.log('');
97
- console.log(chalk.yellow(` ${label}`));
98
- console.log(chalk.gray(' ' +
99
- 'Tarih/Saat'.padEnd(dateW) +
100
- 'Bot'.padEnd(botW) +
101
- 'Son Mesaj'.padEnd(previewW) +
102
- 'Mesaj'.padStart(6) +
103
- ' ID'
104
- ));
105
- console.log(chalk.gray(' ' + '·'.repeat(w - 4)));
106
-
107
- items.forEach(s => {
108
- const d = new Date(s.createdAt);
109
- const time = d.toLocaleString('tr-TR', {
110
- day: '2-digit', month: '2-digit',
111
- hour: '2-digit', minute: '2-digit',
112
- });
113
- const bot = (s.botName || '—').slice(0, botW - 2).padEnd(botW);
114
- const preview = (s.lastMessage || '—').slice(0, previewW - 2).padEnd(previewW);
115
- const msgs = String(s.messageCount).padStart(5);
116
- const id = chalk.gray(s.id.slice(-8));
117
-
118
- console.log(
119
- chalk.gray(' ' + time.padEnd(dateW)) +
120
- chalk.cyan(bot) +
121
- chalk.white(preview) +
122
- chalk.gray(msgs) +
123
- ' ' + id
124
- );
125
- });
126
- });
127
-
128
- console.log('');
129
- console.log(line);
130
- console.log(chalk.gray(` ${active.length} aktif oturum · natureco sessions show <id>`));
131
- console.log(line);
132
- console.log('');
133
- }
134
-
135
- async function showSession(sessionId) {
136
- const apiKey = getApiKey();
137
- const w = process.stdout.columns || 120;
138
- const line = chalk.gray('─'.repeat(w));
139
-
140
- if (!apiKey) {
141
- console.log(chalk.red('\n ❌ Giriş yapılmamış. natureco login\n'));
142
- process.exit(1);
143
- }
144
-
145
- let botList;
146
- try {
147
- botList = await getBots(apiKey);
148
- } catch (err) {
149
- console.log(chalk.red(`\n ❌ Hata: ${err.message}\n`));
150
- process.exit(1);
151
- }
152
-
153
- let session = null;
154
- let botName = null;
155
- for (const bot of (botList?.bots || [])) {
156
- session = loadSession(bot.id, sessionId);
157
- if (session) { botName = bot.name; break; }
158
- }
159
-
160
- if (!session) {
161
- console.log(chalk.red(`\n ❌ Oturum bulunamadı: ${sessionId}\n`));
162
- process.exit(1);
163
- }
164
-
165
- console.log('');
166
- console.log(line);
167
- console.log(chalk.bold.cyan(` Oturum: ${session.id.slice(-8)}`));
168
- console.log(chalk.gray(` Bot: ${botName} · ${new Date(session.createdAt).toLocaleString('tr-TR')} · ${session.messages.length} mesaj`));
169
- console.log(line);
170
- console.log('');
171
-
172
- session.messages.forEach((msg, i) => {
173
- const num = chalk.gray(` ${String(i + 1).padStart(2)}.`);
174
- console.log(num + ' ' + chalk.white('You ') + msg.user);
175
- console.log(' ' + chalk.cyan('Bot ') + msg.bot);
176
- console.log('');
177
- });
178
-
179
- console.log(line);
180
- console.log('');
181
- }
182
-
183
- module.exports = sessions;
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+ const chalk = require('chalk');
5
+ const { listSessions } = require('../utils/sessions');
6
+
7
+ async function sessions(action, ...args) {
8
+ if (!action || action === 'list') return listSessionsCommand();
9
+ if (action === 'delete') {
10
+ const id = args[0];
11
+ if (!id) {
12
+ console.log(chalk.red('\n Session ID gerekli\n'));
13
+ console.log(chalk.gray(' Kullanım: natureco sessions delete <id>\n'));
14
+ process.exit(1);
15
+ }
16
+ return deleteSessionCommand(id);
17
+ }
18
+ if (action === 'show') {
19
+ const sessionId = args[0];
20
+ if (!sessionId) {
21
+ console.log(chalk.red('\n ❌ Session ID gerekli\n'));
22
+ console.log(chalk.gray(' Kullanım: natureco sessions show <id>\n'));
23
+ process.exit(1);
24
+ }
25
+ return showSession(sessionId);
26
+ }
27
+ console.log(chalk.red(`\n ❌ Bilinmeyen komut: ${action}\n`));
28
+ console.log(chalk.gray(' Kullanım: natureco sessions [list|delete|show]\n'));
29
+ process.exit(1);
30
+ }
31
+
32
+ async function listSessionsCommand() {
33
+ const sessions = listSessions();
34
+ if (!sessions.length) {
35
+ console.log(chalk.gray('\n Kayıtlı oturum yok.\n'));
36
+ return;
37
+ }
38
+ sessions.forEach(s => {
39
+ console.log(` [${s.id}] ${s.savedAt.slice(0, 10)} — ${s.preview || '(boş)'} (${s.messageCount} mesaj)`);
40
+ });
41
+ console.log();
42
+ }
43
+
44
+ async function deleteSessionCommand(id) {
45
+ const { deleteSession } = require('../utils/sessions');
46
+ const ok = deleteSession(id);
47
+ console.log(ok ? chalk.green('\n ✓ Oturum silindi.\n') : chalk.red('\n ❌ Oturum bulunamadı.\n'));
48
+ }
49
+
50
+ async function showSession(sessionId) {
51
+ const sessionsDir = path.join(os.homedir(), '.natureco', 'sessions');
52
+ if (!fs.existsSync(sessionsDir)) {
53
+ console.log(chalk.red(`\n ❌ Oturum bulunamadı: ${sessionId}\n`));
54
+ process.exit(1);
55
+ }
56
+ const files = fs.readdirSync(sessionsDir).filter(f => f.includes(sessionId) && f.endsWith('.json'));
57
+ if (!files.length) {
58
+ console.log(chalk.red(`\n ❌ Oturum bulunamadı: ${sessionId}\n`));
59
+ process.exit(1);
60
+ }
61
+ const data = JSON.parse(fs.readFileSync(path.join(sessionsDir, files[0]), 'utf8'));
62
+ console.log(chalk.cyan(`\n Oturum: ${sessionId}`));
63
+ console.log(chalk.gray(` ${data.savedAt} · ${data.messages.length} mesaj\n`));
64
+ data.messages.forEach((msg, i) => {
65
+ console.log(chalk.white(` ${msg.role === 'user' ? 'You' : 'Bot'}: ${msg.content?.slice(0, 200)}`));
66
+ });
67
+ console.log();
68
+ }
69
+
70
+ module.exports = sessions;
@@ -2,7 +2,7 @@ const chalk = require('chalk');
2
2
  const inquirer = require('../utils/inquirer-wrapper');
3
3
  const { getConfig, saveConfig } = require('../utils/config');
4
4
 
5
- async function telegram(action) {
5
+ async function telegram(action, chatId) {
6
6
  if (!action || action === 'connect') {
7
7
  return connectTelegram();
8
8
  }
@@ -16,7 +16,6 @@ async function telegram(action) {
16
16
  }
17
17
 
18
18
  if (action === 'allow') {
19
- const chatId = process.argv[4];
20
19
  if (!chatId) {
21
20
  console.log(chalk.red('\n❌ Chat ID belirtmelisiniz\n'));
22
21
  console.log(chalk.gray('Kullanım: natureco telegram allow <chatId>\n'));
@@ -18,13 +18,6 @@ async function ultrareview(filePath) {
18
18
  const config = getConfig();
19
19
  const defaultBotId = config.defaultBotId || config.botName || 'universal-provider';
20
20
 
21
- // getBots ile gerçek bot ID'yi al
22
- const apiKey = getApiKey();
23
- if (!apiKey && !config.providerApiKey) {
24
- console.log(chalk.red('\n❌ Not logged in. Run "natureco login" first.\n'));
25
- process.exit(1);
26
- }
27
-
28
21
  let botId = defaultBotId;
29
22
  try {
30
23
  const botList = await getBots(apiKey || config.providerApiKey);
@@ -1,5 +1,6 @@
1
1
  const chalk = require('chalk');
2
2
  const { execSync } = require('child_process');
3
+ const semver = require('semver');
3
4
  const inquirer = require('../utils/inquirer-wrapper');
4
5
  const packageJson = require('../../package.json');
5
6
 
@@ -24,7 +25,7 @@ async function update() {
24
25
  }
25
26
 
26
27
  // Versiyon karşılaştırması
27
- const isNewer = compareVersions(latestVersion, currentVersion) > 0;
28
+ const isNewer = semver.gt(latestVersion, currentVersion);
28
29
 
29
30
  if (isNewer) {
30
31
  console.log(chalk.green(`✅ Yeni versiyon mevcut: v${currentVersion} → v${latestVersion}\n`));
@@ -87,20 +88,4 @@ async function update() {
87
88
  }
88
89
  }
89
90
 
90
- // Versiyon karşılaştırma (semver)
91
- function compareVersions(v1, v2) {
92
- const parts1 = v1.split('.').map(Number);
93
- const parts2 = v2.split('.').map(Number);
94
-
95
- for (let i = 0; i < 3; i++) {
96
- const p1 = parts1[i] || 0;
97
- const p2 = parts2[i] || 0;
98
-
99
- if (p1 > p2) return 1;
100
- if (p1 < p2) return -1;
101
- }
102
-
103
- return 0;
104
- }
105
-
106
91
  module.exports = update;
@@ -29,7 +29,7 @@ function loadBaileys() {
29
29
  // WhatsApp session directory
30
30
  const WHATSAPP_SESSION_DIR = path.join(os.homedir(), '.natureco', 'whatsapp-sessions');
31
31
 
32
- async function whatsapp(action) {
32
+ async function whatsapp(action, number) {
33
33
  if (!action || action === 'connect') {
34
34
  return connectWhatsApp();
35
35
  }
@@ -43,7 +43,6 @@ async function whatsapp(action) {
43
43
  }
44
44
 
45
45
  if (action === 'allow') {
46
- const number = process.argv[4];
47
46
  if (!number) {
48
47
  console.log(chalk.red('\n❌ Numara belirtmelisiniz\n'));
49
48
  console.log(chalk.gray('Kullanım: natureco whatsapp allow <numara>\n'));
package/src/tools/bash.js CHANGED
@@ -28,12 +28,14 @@ module.exports = {
28
28
  };
29
29
  }
30
30
 
31
- // Replace /home with actual home directory
31
+ // Replace /home with actual home directory (Unix only)
32
32
  // Handles: /home, /home/Documents, /home/anything
33
33
  let command = params.command;
34
- command = command.replace(/\/home(\/[^\s]*)?/g, (match, subpath) => {
35
- return os.homedir() + (subpath || '');
36
- });
34
+ if (process.platform !== 'win32') {
35
+ command = command.replace(/\/home(\/[^\s]*)?/g, (match, subpath) => {
36
+ return os.homedir() + (subpath || '');
37
+ });
38
+ }
37
39
 
38
40
  const output = execSync(command, {
39
41
  encoding: 'utf-8',
@@ -1,67 +1,7 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ const listDir = require('./list_dir');
3
2
 
4
3
  module.exports = {
4
+ ...listDir,
5
5
  name: 'filesystem',
6
6
  description: 'List files and directories',
7
- inputSchema: {
8
- type: 'object',
9
- properties: {
10
- path: {
11
- type: 'string',
12
- description: 'Directory path to list'
13
- },
14
- recursive: {
15
- type: 'boolean',
16
- description: 'List recursively',
17
- default: false
18
- }
19
- },
20
- required: ['path']
21
- },
22
-
23
- async execute(params) {
24
- try {
25
- const targetPath = path.resolve(params.path);
26
-
27
- if (!fs.existsSync(targetPath)) {
28
- return {
29
- success: false,
30
- error: 'Path does not exist'
31
- };
32
- }
33
-
34
- const stats = fs.statSync(targetPath);
35
-
36
- if (!stats.isDirectory()) {
37
- return {
38
- success: false,
39
- error: 'Path is not a directory'
40
- };
41
- }
42
-
43
- const files = fs.readdirSync(targetPath);
44
- const items = files.map(file => {
45
- const filePath = path.join(targetPath, file);
46
- const fileStats = fs.statSync(filePath);
47
- return {
48
- name: file,
49
- type: fileStats.isDirectory() ? 'directory' : 'file',
50
- size: fileStats.size,
51
- modified: fileStats.mtime
52
- };
53
- });
54
-
55
- return {
56
- success: true,
57
- path: targetPath,
58
- items
59
- };
60
- } catch (error) {
61
- return {
62
- success: false,
63
- error: error.message
64
- };
65
- }
66
- }
67
7
  };
@@ -0,0 +1,39 @@
1
+ const { execSync } = require('child_process');
2
+
3
+ module.exports = {
4
+ name: 'git',
5
+ description: 'Git operations: status, diff, log, branch list, commit',
6
+ inputSchema: {
7
+ type: 'object',
8
+ properties: {
9
+ operation: {
10
+ type: 'string',
11
+ enum: ['status', 'diff', 'log', 'branches', 'add', 'commit'],
12
+ description: 'Git operation to perform'
13
+ },
14
+ args: { type: 'string', description: 'Additional arguments' },
15
+ message: { type: 'string', description: 'Commit message (for commit operation)' }
16
+ },
17
+ required: ['operation']
18
+ },
19
+
20
+ execute({ operation, args = '', message = '' }) {
21
+ const cwd = process.cwd();
22
+ try {
23
+ let cmd;
24
+ switch (operation) {
25
+ case 'status': cmd = 'git status --short'; break;
26
+ case 'diff': cmd = `git diff ${args || 'HEAD'}`; break;
27
+ case 'log': cmd = `git log --oneline ${args || '-10'}`; break;
28
+ case 'branches': cmd = 'git branch -a'; break;
29
+ case 'add': cmd = `git add ${args || '.'}`; break;
30
+ case 'commit': cmd = `git commit -m "${message.replace(/"/g, '\\"')}"`; break;
31
+ default: return { success: false, error: 'Unknown operation' };
32
+ }
33
+ const output = execSync(cmd, { cwd, stdio: 'pipe', encoding: 'utf8' });
34
+ return { success: true, output: output.trim() };
35
+ } catch (err) {
36
+ return { success: false, error: err.stderr?.toString() || err.message };
37
+ }
38
+ }
39
+ };
@@ -27,10 +27,12 @@ module.exports = {
27
27
  let dirPath = params.path || '.';
28
28
  dirPath = dirPath.replace(/^~/, os.homedir());
29
29
 
30
- // Fix /home path - replace with actual home directory
30
+ // Fix /home path - replace with actual home directory (Unix only)
31
31
  // Handles: /home, home, /home/Documents, /home/anything
32
- if (dirPath === '/home' || dirPath === 'home' || dirPath.startsWith('/home/')) {
33
- dirPath = dirPath.replace(/^\/home/, os.homedir());
32
+ if (process.platform !== 'win32') {
33
+ if (dirPath === '/home' || dirPath === 'home' || dirPath.startsWith('/home/')) {
34
+ dirPath = dirPath.replace(/^\/home/, os.homedir());
35
+ }
34
36
  }
35
37
 
36
38
  const absolutePath = path.resolve(dirPath);
@@ -1,16 +1,19 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const AGENTS_FILE = path.join(process.cwd(), '.natureco', 'AGENTS.md');
4
+ function getAgentsFilePath() {
5
+ return path.join(process.cwd(), '.natureco', 'AGENTS.md');
6
+ }
5
7
 
6
8
  // Read AGENTS.md content
7
9
  function getAgentsPrompt() {
8
- if (!fs.existsSync(AGENTS_FILE)) {
10
+ const agentsFile = getAgentsFilePath();
11
+ if (!fs.existsSync(agentsFile)) {
9
12
  return '';
10
13
  }
11
14
 
12
15
  try {
13
- const content = fs.readFileSync(AGENTS_FILE, 'utf8');
16
+ const content = fs.readFileSync(agentsFile, 'utf8');
14
17
  return content.trim();
15
18
  } catch {
16
19
  return '';
@@ -19,7 +22,7 @@ function getAgentsPrompt() {
19
22
 
20
23
  // Check if AGENTS.md exists
21
24
  function hasAgentsFile() {
22
- return fs.existsSync(AGENTS_FILE);
25
+ return fs.existsSync(getAgentsFilePath());
23
26
  }
24
27
 
25
28
  module.exports = {