natureco-cli 2.12.4 → 2.12.7
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/cron.js +27 -1
- package/src/commands/dashboard.js +2 -2
- package/src/commands/migrate.js +80 -4
package/package.json
CHANGED
package/src/commands/cron.js
CHANGED
|
@@ -5,6 +5,17 @@ const os = require('os');
|
|
|
5
5
|
|
|
6
6
|
const CRONS_FILE = path.join(os.homedir(), '.natureco', 'crons.json');
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Normalize WhatsApp number from JID format to clean phone number
|
|
10
|
+
* "905422842631:49@s.whatsapp.net" → "+905422842631"
|
|
11
|
+
*/
|
|
12
|
+
function normalizeWhatsAppNumber(target) {
|
|
13
|
+
if (!target) return target;
|
|
14
|
+
// Extract digits from JID format
|
|
15
|
+
const match = target.match(/^(\d+)/);
|
|
16
|
+
return match ? '+' + match[1] : target;
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
function loadCrons() {
|
|
9
20
|
try {
|
|
10
21
|
if (!fs.existsSync(CRONS_FILE)) {
|
|
@@ -113,12 +124,27 @@ function listCrons() {
|
|
|
113
124
|
return;
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
// Load config for fallback targets
|
|
128
|
+
const { getConfig } = require('../utils/config');
|
|
129
|
+
const config = getConfig();
|
|
130
|
+
const defaultWhatsappTarget = normalizeWhatsAppNumber(config.whatsappPhone) || 'N/A';
|
|
131
|
+
const defaultTelegramTarget = (config.telegramAllowedChats && config.telegramAllowedChats[0]) || 'N/A';
|
|
132
|
+
|
|
116
133
|
console.log(chalk.green(`\n📅 Kayıtlı Cron'lar (${crons.length})\n`));
|
|
117
134
|
|
|
118
135
|
crons.forEach((c, i) => {
|
|
136
|
+
// Use target from cron or fallback to config
|
|
137
|
+
let target = c.target;
|
|
138
|
+
if (!target || target === 'undefined') {
|
|
139
|
+
target = c.action === 'telegram' ? defaultTelegramTarget : defaultWhatsappTarget;
|
|
140
|
+
} else if (c.action === 'whatsapp') {
|
|
141
|
+
// Normalize WhatsApp JID format
|
|
142
|
+
target = normalizeWhatsAppNumber(target);
|
|
143
|
+
}
|
|
144
|
+
|
|
119
145
|
console.log(chalk.cyan(`${i + 1}. ${c.name}`));
|
|
120
146
|
console.log(chalk.gray(` Zamanlama: ${c.schedule}`));
|
|
121
|
-
console.log(chalk.gray(` Kanal: ${c.action} → ${
|
|
147
|
+
console.log(chalk.gray(` Kanal: ${c.action} → ${target}`));
|
|
122
148
|
console.log(chalk.gray(` Prompt: ${c.prompt.substring(0, 60)}${c.prompt.length > 60 ? '...' : ''}`));
|
|
123
149
|
console.log(chalk.gray(` Durum: ${c.enabled ? '✅ Aktif' : '❌ Pasif'}`));
|
|
124
150
|
console.log('');
|
|
@@ -211,7 +211,7 @@ body::before{
|
|
|
211
211
|
<div class="header-bot-name" id="header-bot-name">Nature Bot</div>
|
|
212
212
|
<div class="header-bot-model" id="header-bot-model">NatureCo</div>
|
|
213
213
|
</div>
|
|
214
|
-
<div class="version-badge" id="version-badge">v2.12.
|
|
214
|
+
<div class="version-badge" id="version-badge">v2.12.7</div>
|
|
215
215
|
</div>
|
|
216
216
|
<div class="messages" id="messages"></div>
|
|
217
217
|
<div class="input-area">
|
|
@@ -341,7 +341,7 @@ function dashboard(action) {
|
|
|
341
341
|
apiKey: cfg.apiKey,
|
|
342
342
|
defaultBot: cfg.defaultBot,
|
|
343
343
|
defaultBotId: cfg.defaultBotId,
|
|
344
|
-
version: 'v2.12.
|
|
344
|
+
version: 'v2.12.7',
|
|
345
345
|
bots: cfg.bots || [],
|
|
346
346
|
telegramToken: cfg.telegramToken || null,
|
|
347
347
|
whatsappConnected: cfg.whatsappConnected || false,
|
package/src/commands/migrate.js
CHANGED
|
@@ -4,6 +4,17 @@ const os = require('os');
|
|
|
4
4
|
const chalk = require('chalk');
|
|
5
5
|
const { getConfig, setConfig } = require('../utils/config');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Normalize WhatsApp number from JID format to clean phone number
|
|
9
|
+
* "905422842631:49@s.whatsapp.net" → "+905422842631"
|
|
10
|
+
*/
|
|
11
|
+
function normalizeWhatsAppNumber(target) {
|
|
12
|
+
if (!target) return target;
|
|
13
|
+
// Extract digits from JID format
|
|
14
|
+
const match = target.match(/^(\d+)/);
|
|
15
|
+
return match ? '+' + match[1] : target;
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
async function migrate(options) {
|
|
8
19
|
const from = options.from || 'openclaw';
|
|
9
20
|
|
|
@@ -32,6 +43,7 @@ async function migrate(options) {
|
|
|
32
43
|
crons: { total: 0, active: 0, inactive: 0 },
|
|
33
44
|
telegram: null,
|
|
34
45
|
whatsapp: false,
|
|
46
|
+
scripts: 0,
|
|
35
47
|
};
|
|
36
48
|
|
|
37
49
|
// 1. Memory migration
|
|
@@ -79,6 +91,48 @@ async function migrate(options) {
|
|
|
79
91
|
console.log(chalk.gray('⚠️ Memory migration atlandı:', err.message));
|
|
80
92
|
}
|
|
81
93
|
|
|
94
|
+
// 1.5. Workspace scripts migration
|
|
95
|
+
try {
|
|
96
|
+
const scriptsSourceDir = path.join(openclawDir, 'workspace', 'scripts');
|
|
97
|
+
|
|
98
|
+
if (fs.existsSync(scriptsSourceDir)) {
|
|
99
|
+
const scriptsDestDir = path.join(os.homedir(), '.natureco', 'workspace', 'scripts');
|
|
100
|
+
fs.mkdirSync(scriptsDestDir, { recursive: true });
|
|
101
|
+
|
|
102
|
+
// Copy all files and fix paths
|
|
103
|
+
const files = fs.readdirSync(scriptsSourceDir);
|
|
104
|
+
|
|
105
|
+
for (const file of files) {
|
|
106
|
+
const sourcePath = path.join(scriptsSourceDir, file);
|
|
107
|
+
const destPath = path.join(scriptsDestDir, file);
|
|
108
|
+
|
|
109
|
+
// Skip directories
|
|
110
|
+
if (fs.statSync(sourcePath).isDirectory()) continue;
|
|
111
|
+
|
|
112
|
+
// Read file content
|
|
113
|
+
let content = fs.readFileSync(sourcePath, 'utf8');
|
|
114
|
+
|
|
115
|
+
// Fix Windows paths in .js files
|
|
116
|
+
if (file.endsWith('.js')) {
|
|
117
|
+
// C:\Users\user\.openclaw\ → ~/.natureco/
|
|
118
|
+
content = content.replace(/C:\\Users\\[^\\]+\\.openclaw\\/g, '~/.natureco/');
|
|
119
|
+
// E:\.openclaw\ → ~/.natureco/
|
|
120
|
+
content = content.replace(/E:\\.openclaw\\/g, '~/.natureco/');
|
|
121
|
+
// C:\Users\user\ → ~/
|
|
122
|
+
content = content.replace(/C:\\Users\\[^\\]+\\/g, '~/');
|
|
123
|
+
// General .openclaw path fix
|
|
124
|
+
content = content.replace(/\\.openclaw\\/g, '/.natureco/');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Write fixed content
|
|
128
|
+
fs.writeFileSync(destPath, content);
|
|
129
|
+
report.scripts++;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.log(chalk.gray('⚠️ Workspace scripts migration atlandı:', err.message));
|
|
134
|
+
}
|
|
135
|
+
|
|
82
136
|
// 2. Cron jobs migration
|
|
83
137
|
try {
|
|
84
138
|
const cronJobsPath = path.join(openclawDir, 'cron', 'jobs.json');
|
|
@@ -90,7 +144,7 @@ async function migrate(options) {
|
|
|
90
144
|
|
|
91
145
|
// Get WhatsApp target from config
|
|
92
146
|
const config = getConfig();
|
|
93
|
-
const whatsappTarget = config.whatsappPhone || '+905422842631'; // fallback
|
|
147
|
+
const whatsappTarget = normalizeWhatsAppNumber(config.whatsappPhone) || '+905422842631'; // fallback
|
|
94
148
|
|
|
95
149
|
const naturecoCrons = [];
|
|
96
150
|
|
|
@@ -122,6 +176,14 @@ async function migrate(options) {
|
|
|
122
176
|
|
|
123
177
|
// Get prompt (max 300 chars)
|
|
124
178
|
let prompt = job.payload?.message || '';
|
|
179
|
+
|
|
180
|
+
// Fix Windows paths in prompts
|
|
181
|
+
// "node C:\Users\user\.openclaw\workspace\scripts\xxx.js" → "node ~/.natureco/workspace/scripts/xxx.js"
|
|
182
|
+
prompt = prompt.replace(/C:\\Users\\[^\\]+\\.openclaw\\/g, '~/.natureco/');
|
|
183
|
+
prompt = prompt.replace(/E:\\.openclaw\\/g, '~/.natureco/');
|
|
184
|
+
prompt = prompt.replace(/C:\\Users\\[^\\]+\\/g, '~/');
|
|
185
|
+
prompt = prompt.replace(/\\.openclaw\\/g, '/.natureco/');
|
|
186
|
+
|
|
125
187
|
if (prompt.length > 300) {
|
|
126
188
|
prompt = prompt.slice(0, 300);
|
|
127
189
|
}
|
|
@@ -130,7 +192,7 @@ async function migrate(options) {
|
|
|
130
192
|
name: job.name || 'Unnamed Job',
|
|
131
193
|
schedule: job.schedule.expr,
|
|
132
194
|
action: action,
|
|
133
|
-
target: target,
|
|
195
|
+
target: target, // Already normalized for WhatsApp
|
|
134
196
|
prompt: prompt,
|
|
135
197
|
enabled: true, // Enable migrated crons
|
|
136
198
|
});
|
|
@@ -139,14 +201,24 @@ async function migrate(options) {
|
|
|
139
201
|
// Save to NatureCo crons
|
|
140
202
|
const cronsFile = path.join(os.homedir(), '.natureco', 'crons.json');
|
|
141
203
|
|
|
142
|
-
//
|
|
204
|
+
// Load existing crons and check for duplicates by name
|
|
143
205
|
let existingCrons = [];
|
|
144
206
|
if (fs.existsSync(cronsFile)) {
|
|
145
207
|
existingCrons = JSON.parse(fs.readFileSync(cronsFile, 'utf8'));
|
|
146
208
|
}
|
|
147
209
|
|
|
148
|
-
|
|
210
|
+
// Filter out duplicates (check by name)
|
|
211
|
+
const existingNames = existingCrons.map(c => c.name);
|
|
212
|
+
const toAdd = naturecoCrons.filter(c => !existingNames.includes(c.name));
|
|
213
|
+
|
|
214
|
+
// Merge without duplicates
|
|
215
|
+
const mergedCrons = [...existingCrons, ...toAdd];
|
|
149
216
|
fs.writeFileSync(cronsFile, JSON.stringify(mergedCrons, null, 2));
|
|
217
|
+
|
|
218
|
+
// Update report with actual added count
|
|
219
|
+
if (toAdd.length < naturecoCrons.length) {
|
|
220
|
+
console.log(chalk.yellow(`⚠️ ${naturecoCrons.length - toAdd.length} cron zaten mevcut, atlandı`));
|
|
221
|
+
}
|
|
150
222
|
}
|
|
151
223
|
} catch (err) {
|
|
152
224
|
console.log(chalk.gray('⚠️ Cron migration atlandı:', err.message));
|
|
@@ -197,6 +269,10 @@ async function migrate(options) {
|
|
|
197
269
|
console.log(chalk.green('✅ Memory:'), chalk.white(`${report.memory.name || 'N/A'}${facts ? ', ' + facts : ''}`));
|
|
198
270
|
}
|
|
199
271
|
|
|
272
|
+
if (report.scripts > 0) {
|
|
273
|
+
console.log(chalk.green('✅ Scripts:'), chalk.white(`${report.scripts} script kopyalandı ve path'ler güncellendi`));
|
|
274
|
+
}
|
|
275
|
+
|
|
200
276
|
if (report.crons.total > 0) {
|
|
201
277
|
console.log(chalk.green('✅ Cron jobs:'), chalk.white(`${report.crons.total} job bulundu (${report.crons.active} aktif migrate edildi, ${report.crons.inactive} pasif atlandı)`));
|
|
202
278
|
}
|