clawflowbang 1.0.0

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.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Cron commands - จัดการ cronjobs
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const ClawFlow = require('../index');
7
+ const { normalizeCronExpression } = require('../core/CronFormat');
8
+
9
+ function parseJsonParams(params) {
10
+ if (params === undefined || params === null || params === '') {
11
+ return {};
12
+ }
13
+
14
+ if (typeof params === 'object') {
15
+ return params;
16
+ }
17
+
18
+ return JSON.parse(params);
19
+ }
20
+
21
+ function resolveScheduleInput(options) {
22
+ if (options.every) {
23
+ return normalizeCronExpression(`every ${options.every}`);
24
+ }
25
+
26
+ return normalizeCronExpression(options.schedule || '*/5 * * * *');
27
+ }
28
+
29
+ module.exports = {
30
+ async list() {
31
+ const hub = new ClawFlow();
32
+
33
+ try {
34
+ console.log(chalk.cyan.bold('\n⏰ Cronjobs ที่ตั้งไว้:\n'));
35
+
36
+ const crons = await hub.listCrons();
37
+
38
+ if (crons.length === 0) {
39
+ console.log(chalk.gray(' ไม่มี cronjobs'));
40
+ } else {
41
+ crons.forEach((job) => {
42
+ const status = job.enabled !== false ? chalk.green('●') : chalk.gray('○');
43
+ console.log(` ${status} ${chalk.bold(job.skill || job.name)}`);
44
+ console.log(` ${chalk.blue('Schedule:')} ${job.schedule}`);
45
+ console.log(` ${chalk.blue('Description:')} ${job.description || '-'}`);
46
+ console.log();
47
+ });
48
+ }
49
+ } catch (error) {
50
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
51
+ process.exit(1);
52
+ }
53
+ },
54
+
55
+ async add(skillName, options) {
56
+ const { params = '{}', description = '' } = options;
57
+
58
+ const hub = new ClawFlow();
59
+
60
+ try {
61
+ const parsedParams = parseJsonParams(params);
62
+ const schedule = resolveScheduleInput(options);
63
+
64
+ console.log(chalk.cyan(`\n➕ กำลังเพิ่ม cronjob สำหรับ ${chalk.bold(skillName)}...\n`));
65
+
66
+ const job = await hub.cronManager.add(skillName, schedule, parsedParams, description);
67
+
68
+ console.log(chalk.green(`\n✓ เพิ่ม cronjob สำเร็จ`));
69
+ console.log(` ID: ${job.id}`);
70
+ console.log(` Schedule: ${job.schedule}`);
71
+ } catch (error) {
72
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
73
+ process.exit(1);
74
+ }
75
+ },
76
+
77
+ async remove(jobId) {
78
+ const hub = new ClawFlow();
79
+
80
+ try {
81
+ console.log(chalk.cyan(`\n🗑️ กำลังลบ cronjob ${chalk.bold(jobId)}...\n`));
82
+
83
+ await hub.cronManager.remove(jobId);
84
+
85
+ console.log(chalk.green(`\n✓ ลบ cronjob สำเร็จ`));
86
+ } catch (error) {
87
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
88
+ process.exit(1);
89
+ }
90
+ },
91
+
92
+ async edit(jobId, options) {
93
+ const hub = new ClawFlow();
94
+
95
+ try {
96
+ const updates = {};
97
+ if (options.schedule || options.every) {
98
+ updates.schedule = resolveScheduleInput(options);
99
+ }
100
+ if (typeof options.description === 'string') {
101
+ updates.description = options.description;
102
+ }
103
+ if (options.params !== undefined) {
104
+ updates.params = parseJsonParams(options.params);
105
+ }
106
+
107
+ if (Object.keys(updates).length === 0) {
108
+ throw new Error('ไม่มีข้อมูลสำหรับแก้ไข (ใช้ --schedule/--every/--description/--params)');
109
+ }
110
+
111
+ const updated = await hub.cronManager.edit(jobId, updates);
112
+
113
+ console.log(chalk.green(`\n✓ แก้ไข cronjob สำเร็จ`));
114
+ console.log(` ID: ${updated.id || jobId}`);
115
+ if (updated.schedule) {
116
+ console.log(` Schedule: ${updated.schedule}`);
117
+ }
118
+ } catch (error) {
119
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
120
+ process.exit(1);
121
+ }
122
+ },
123
+ };
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Init command - เริ่มต้นใช้งาน ClawFlow
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const fs = require('fs-extra');
7
+ const path = require('path');
8
+ const inquirer = require('inquirer');
9
+
10
+ module.exports = async function initCommand(options) {
11
+ const { force = false } = options;
12
+
13
+ const cwd = process.cwd();
14
+ const configDir = path.join(cwd, '.clawflowhub');
15
+ const configFile = path.join(configDir, 'config.json');
16
+
17
+ console.log(chalk.cyan.bold('\n🚀 เริ่มต้นใช้งาน ClawFlow\n'));
18
+
19
+ // ตรวจสอบว่ามี config อยู่แล้วหรือไม่
20
+ if (fs.existsSync(configFile) && !force) {
21
+ console.log(chalk.yellow('⚠️ พบการตั้งค่าเดิมในโฟลเดอร์นี้'));
22
+ const { overwrite } = await inquirer.prompt([
23
+ {
24
+ type: 'confirm',
25
+ name: 'overwrite',
26
+ message: 'ต้องการเขียนทับการตั้งค่าเดิมหรือไม่?',
27
+ default: false,
28
+ },
29
+ ]);
30
+
31
+ if (!overwrite) {
32
+ console.log(chalk.gray(' ยกเลิกการดำเนินการ'));
33
+ return;
34
+ }
35
+ }
36
+
37
+ // ถามค่าการตั้งค่า
38
+ const answers = await inquirer.prompt([
39
+ {
40
+ type: 'input',
41
+ name: 'skillsPath',
42
+ message: 'โฟลเดอร์สำหรับเก็บ skills:',
43
+ default: './skills',
44
+ },
45
+ {
46
+ type: 'input',
47
+ name: 'openclawBin',
48
+ message: 'Path ของ openclaw CLI:',
49
+ default: 'openclaw',
50
+ },
51
+ {
52
+ type: 'input',
53
+ name: 'clawhubBin',
54
+ message: 'Path ของ clawhub CLI:',
55
+ default: 'clawhub',
56
+ },
57
+ {
58
+ type: 'confirm',
59
+ name: 'enableNpmRegistry',
60
+ message: 'เปิดใช้งาน NPM Registry (ค้นหา packages จาก npm)?',
61
+ default: true,
62
+ },
63
+ ]);
64
+
65
+ // สร้าง config
66
+ const config = {
67
+ version: '1.0.0',
68
+ openclaw: {
69
+ baseUrl: 'http://localhost:3000',
70
+ apiKey: null,
71
+ cliBin: answers.openclawBin,
72
+ clawhubBin: answers.clawhubBin,
73
+ workspacePath: path.join(cwd, '.openclaw'),
74
+ skillsPath: path.resolve(cwd, answers.skillsPath),
75
+ cronJobsFile: path.join(cwd, '.clawflowhub', 'cron-jobs.json'),
76
+ },
77
+ registry: {
78
+ url: 'https://registry.clawflowhub.dev',
79
+ cacheExpiry: 3600,
80
+ enableNpm: answers.enableNpmRegistry,
81
+ },
82
+ cron: {
83
+ enabled: true,
84
+ logLevel: 'info',
85
+ maxConcurrentJobs: 5,
86
+ },
87
+ installed: {},
88
+ crons: [],
89
+ lastUpdate: new Date().toISOString(),
90
+ };
91
+
92
+ // สร้างโฟลเดอร์และเขียน config
93
+ fs.ensureDirSync(configDir);
94
+ fs.ensureDirSync(path.resolve(cwd, answers.skillsPath));
95
+ fs.writeJsonSync(configFile, config, { spaces: 2 });
96
+
97
+ // สร้าง .gitignore
98
+ const gitignorePath = path.join(configDir, '.gitignore');
99
+ if (!fs.existsSync(gitignorePath)) {
100
+ fs.writeFileSync(gitignorePath, 'npm-cache/\nlogs/\n*.log\n');
101
+ }
102
+
103
+ console.log(chalk.green('\n✓ สร้างการตั้งค่าเสร็จสิ้น'));
104
+ console.log(chalk.gray(` Config: ${configFile}`));
105
+ console.log(chalk.gray(` Skills: ${config.openclaw.skillsPath}`));
106
+ console.log();
107
+ console.log(chalk.cyan('คำสั่งที่ใช้ได้:'));
108
+ console.log(' clawflow install <package> - ติดตั้ง package');
109
+ console.log(' clawflow list - แสดงรายการ packages');
110
+ console.log(' clawflow search <query> - ค้นหา packages');
111
+ console.log();
112
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Install Command - ติดตั้ง package พร้อม skills และ cronjobs
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const ClawFlow = require('../index');
7
+
8
+ module.exports = async function installCommand(packageName, options) {
9
+ try {
10
+ const cfh = new ClawFlow({
11
+ configPath: options.config,
12
+ skillsPath: options.skillsPath,
13
+ cronJobsFile: options.cronJobs,
14
+ openclawBin: options.openclawBin,
15
+ clawhubBin: options.clawhubBin,
16
+ });
17
+
18
+ const result = await cfh.install(packageName, {
19
+ global: options.global,
20
+ cron: options.cron,
21
+ dryRun: options.dryRun,
22
+ });
23
+
24
+ if (result.success) {
25
+ console.log(chalk.green('\n🎉 ติดตั้งสำเร็จ!'));
26
+
27
+ if (!result.dryRun) {
28
+ console.log(chalk.gray('\nใช้คำสั่งต่อไปนี้เพื่อดูรายละเอียด:'));
29
+ console.log(chalk.cyan(` clawflow status`));
30
+ console.log(chalk.cyan(` clawflow cron-list`));
31
+ }
32
+ }
33
+
34
+ } catch (error) {
35
+ console.error(chalk.red('\n❌ ติดตั้งไม่สำเร็จ:'), error.message);
36
+ process.exit(1);
37
+ }
38
+ };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * List command - แสดงรายการ packages
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const ClawFlow = require('../index');
7
+
8
+ module.exports = async function listCommand(options) {
9
+ const { available = false, npm = false } = options;
10
+
11
+ const hub = new ClawFlow();
12
+
13
+ try {
14
+ if (available || npm) {
15
+ // แสดง packages ที่พร้อมติดตั้ง
16
+ console.log(chalk.cyan.bold('\n📦 Packages ที่พร้อมติดตั้ง:\n'));
17
+
18
+ const packages = await hub.registry.getAvailablePackages({
19
+ includeNpm: npm || true,
20
+ });
21
+
22
+ if (packages.length === 0) {
23
+ console.log(chalk.gray(' ไม่พบ packages'));
24
+ } else {
25
+ // แยกตาม source
26
+ const builtins = packages.filter((p) => p.source === 'builtin');
27
+ const npms = packages.filter((p) => p.source === 'npm');
28
+
29
+ if (builtins.length > 0) {
30
+ console.log(chalk.yellow(' Built-in Packages:'));
31
+ builtins.forEach((pkg) => {
32
+ console.log(` ${chalk.green('●')} ${chalk.bold(pkg.name)}@${pkg.version}`);
33
+ console.log(` ${chalk.gray(pkg.description || 'ไม่มีคำอธิบาย')}`);
34
+ console.log(` ${chalk.blue('Skills:')} ${pkg.skills} | ${chalk.blue('Crons:')} ${pkg.crons}`);
35
+ console.log();
36
+ });
37
+ }
38
+
39
+ if (npms.length > 0) {
40
+ console.log(chalk.yellow(' NPM Packages:'));
41
+ npms.forEach((pkg) => {
42
+ console.log(` ${chalk.green('◆')} ${chalk.bold(pkg.name)}@${pkg.version}`);
43
+ console.log(` ${chalk.gray(pkg.description || 'ไม่มีคำอธิบาย')}`);
44
+ console.log(` ${chalk.blue('Author:')} ${pkg.author}`);
45
+ console.log();
46
+ });
47
+ }
48
+ }
49
+ } else {
50
+ // แสดง packages ที่ติดตั้งแล้ว
51
+ console.log(chalk.cyan.bold('\n📦 Packages ที่ติดตั้งแล้ว:\n'));
52
+
53
+ const installed = await hub.registry.getInstalledPackages();
54
+ const entries = Object.entries(installed);
55
+
56
+ if (entries.length === 0) {
57
+ console.log(chalk.gray(' ยังไม่มี packages ที่ติดตั้ง'));
58
+ console.log(chalk.gray(' ใช้ "clawflow install <package>" เพื่อติดตั้ง'));
59
+ } else {
60
+ entries.forEach(([name, info]) => {
61
+ console.log(` ${chalk.green('✓')} ${chalk.bold(name)}@${info.version}`);
62
+ console.log(` ${chalk.blue('ติดตั้งเมื่อ:')} ${new Date(info.installedAt).toLocaleString()}`);
63
+ if (info.skills?.length > 0) {
64
+ console.log(` ${chalk.blue('Skills:')} ${info.skills.join(', ')}`);
65
+ }
66
+ if (info.crons?.length > 0) {
67
+ console.log(` ${chalk.blue('Cronjobs:')} ${info.crons.length} รายการ`);
68
+ }
69
+ console.log();
70
+ });
71
+ }
72
+ }
73
+ } catch (error) {
74
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
75
+ process.exit(1);
76
+ }
77
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Remove command - ถอนการติดตั้ง package
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const ClawFlow = require('../index');
7
+
8
+ module.exports = async function removeCommand(packageName, options) {
9
+ const { global = false, keepConfig = false } = options;
10
+
11
+ const hub = new ClawFlow();
12
+
13
+ try {
14
+ console.log(chalk.cyan(`\n🗑️ กำลังถอนการติดตั้ง ${chalk.bold(packageName)}...\n`));
15
+
16
+ const result = await hub.remove(packageName, { global, keepConfig });
17
+
18
+ if (result.success) {
19
+ console.log(chalk.green(`\n✓ ถอนการติดตั้ง ${packageName} สำเร็จ`));
20
+ } else {
21
+ console.log(chalk.yellow(`\n⚠️ ${result.reason || 'ไม่สามารถถอนการติดตั้งได้'}`));
22
+ }
23
+ } catch (error) {
24
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
25
+ process.exit(1);
26
+ }
27
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Search command - ค้นหา packages
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const ClawFlow = require('../index');
7
+
8
+ module.exports = async function searchCommand(query, options) {
9
+ const { npm = true } = options;
10
+
11
+ if (!query) {
12
+ console.log(chalk.yellow('⚠️ กรุณาระบุคำค้นหา'));
13
+ console.log(chalk.gray(' ตัวอย่าง: clawflow search trading'));
14
+ process.exit(1);
15
+ }
16
+
17
+ const hub = new ClawFlow();
18
+
19
+ try {
20
+ console.log(chalk.cyan(`\n🔍 กำลังค้นหา "${query}"...\n`));
21
+
22
+ const results = await hub.registry.searchPackages(query, {
23
+ includeNpm: npm,
24
+ limit: 50,
25
+ });
26
+
27
+ if (results.length === 0) {
28
+ console.log(chalk.yellow(' ไม่พบ packages ที่ตรงกับคำค้นหา'));
29
+ console.log(chalk.gray(' ลองใช้คำค้นหาอื่น หรือตรวจสอบการเชื่อมต่ออินเทอร์เน็ต'));
30
+ } else {
31
+ console.log(chalk.green(` พบ ${results.length} packages:\n`));
32
+
33
+ results.forEach((pkg) => {
34
+ const icon = pkg.source === 'builtin' ? '●' : '◆';
35
+ const sourceLabel = pkg.source === 'builtin' ? chalk.gray('[built-in]') : chalk.blue('[npm]');
36
+
37
+ console.log(` ${chalk.green(icon)} ${chalk.bold(pkg.name)}@${pkg.version} ${sourceLabel}`);
38
+ console.log(` ${chalk.gray(pkg.description || 'ไม่มีคำอธิบาย')}`);
39
+
40
+ if (pkg.skills?.length > 0) {
41
+ console.log(` ${chalk.blue('Skills:')} ${pkg.skills.map((s) => s.name || s).join(', ')}`);
42
+ }
43
+
44
+ if (pkg.crons?.length > 0) {
45
+ console.log(` ${chalk.blue('Cronjobs:')} ${pkg.crons.length} รายการ`);
46
+ }
47
+
48
+ if (pkg.source === 'npm' && pkg.author) {
49
+ console.log(` ${chalk.blue('Author:')} ${pkg.author}`);
50
+ }
51
+
52
+ console.log();
53
+ });
54
+
55
+ console.log(chalk.gray(' ใช้ "clawflow install <package-name>" เพื่อติดตั้ง'));
56
+ }
57
+ } catch (error) {
58
+ console.error(chalk.red(`\n❌ Error: ${error.message}`));
59
+ process.exit(1);
60
+ }
61
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Status command - แสดงสถานะระบบ
3
+ */
4
+
5
+ const chalk = require('chalk');
6
+ const os = require('os');
7
+ const ClawFlow = require('../index');
8
+ const OpenClawCLI = require('../core/OpenClawCLI');
9
+
10
+ module.exports = async function statusCommand() {
11
+ const hub = new ClawFlow();
12
+ const openclawCLI = new OpenClawCLI(hub.config);
13
+
14
+ console.log(chalk.cyan.bold('\n📊 สถานะระบบ ClawFlow\n'));
15
+
16
+ // System Info
17
+ console.log(chalk.yellow('System:'));
18
+ console.log(` Node.js: ${process.version}`);
19
+ console.log(` Platform: ${process.platform} (${os.arch()})`);
20
+ console.log(` Home: ${os.homedir()}`);
21
+ console.log();
22
+
23
+ // ClawFlow Config
24
+ console.log(chalk.yellow('ClawFlow:'));
25
+ console.log(` Config Path: ${hub.config.getConfigPath()}`);
26
+ console.log(` Skills Path: ${hub.config.getSkillsPath()}`);
27
+ console.log(` Cron Jobs File: ${hub.config.getCronJobsFilePath()}`);
28
+ console.log();
29
+
30
+ // OpenClaw Integration
31
+ console.log(chalk.yellow('OpenClaw Integration:'));
32
+ const hasOpenClaw = openclawCLI.hasOpenClaw();
33
+ const hasClawhub = openclawCLI.hasClawhub();
34
+
35
+ console.log(` openclaw CLI: ${hasOpenClaw ? chalk.green('✓ พบ') : chalk.red('✗ ไม่พบ')}`);
36
+ console.log(` clawhub CLI: ${hasClawhub ? chalk.green('✓ พบ') : chalk.red('✗ ไม่พบ')}`);
37
+ console.log();
38
+
39
+ // Installed Packages
40
+ const installed = await hub.listInstalled();
41
+ const installedCount = Object.keys(installed).length;
42
+
43
+ console.log(chalk.yellow('Packages:'));
44
+ console.log(` Installed: ${installedCount} packages`);
45
+
46
+ if (installedCount > 0) {
47
+ Object.entries(installed).forEach(([name, info]) => {
48
+ console.log(` - ${name}@${info.version}`);
49
+ });
50
+ }
51
+ console.log();
52
+
53
+ // Cron Jobs
54
+ const crons = await hub.listCrons();
55
+ console.log(chalk.yellow('Cron Jobs:'));
56
+ console.log(` Total: ${crons.length} jobs`);
57
+ console.log(` Enabled: ${crons.filter((c) => c.enabled !== false).length} jobs`);
58
+ console.log();
59
+
60
+ // NPM Registry
61
+ console.log(chalk.yellow('NPM Registry:'));
62
+ console.log(` URL: https://registry.npmjs.org`);
63
+ console.log(` Cache: Enabled (5 minutes)`);
64
+ console.log();
65
+
66
+ console.log(chalk.green('✓ ระบบพร้อมใช้งาน'));
67
+ console.log();
68
+ };