create-openclaw-bot 5.8.0 → 5.8.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/README.vi.md CHANGED
@@ -1,164 +1,162 @@
1
- <div align="center">
2
-
3
- # 🦞 OpenClaw Setup
4
-
5
- <p align="center">
6
- <a href="https://github.com/tuanminhhole/openclaw-setup/releases"><img src="https://img.shields.io/badge/RELEASE-v5.8.0-0EA5E9?style=for-the-badge" alt="Version 5.8.0" /></a>
7
- <a href="https://github.com/tuanminhhole/openclaw-setup?tab=MIT-1-ov-file"><img src="https://img.shields.io/badge/LICENSE-MIT-success?style=for-the-badge" alt="MIT License" /></a>
8
- <a href="https://www.npmjs.com/package/create-openclaw-bot"><img src="https://img.shields.io/npm/v/create-openclaw-bot?style=for-the-badge&label=CLI&color=2563EB&logo=npm&logoColor=white" alt="NPM Version" /></a>
9
- <a href="https://github.com/tuanminhhole/openclaw-setup/stargazers"><img src="https://img.shields.io/github/stars/tuanminhhole/openclaw-setup?style=for-the-badge&color=eab308&logo=github&logoColor=white" alt="GitHub Stars" /></a>
10
- </p>
11
-
12
- <p style="margin-top: 16px;">
13
- <img src="https://flagcdn.com/24x18/vn.png" alt="Tiếng Việt" width="24" height="18" style="vertical-align: sub;"> <strong>Tiếng Việt</strong> ·
14
- <img src="https://flagcdn.com/24x18/gb.png" alt="English" width="24" height="18" style="vertical-align: sub;"> <a href="README.md">English</a>
15
- </p>
16
-
17
- Trình cài đặt và quản trị **Web UI Setup** thế hệ mới giúp tự động hóa 100% quá trình tạo dự án, triển khai quản lý đa bot AI miễn phí trên Telegram hoặc Zalo — hỗ trợ **Windows, macOS, Ubuntu, VPS**.
18
-
19
- <p align="center" style="margin: 24px 0;">
20
- <img src="https://raw.githubusercontent.com/tuanminhhole/openclaw-setup/main/docs/openclaw-setup.png" alt="OpenClaw Setup" width="49%" style="border-radius: 8px; border: 1px solid #333;" />
21
- <img src="https://raw.githubusercontent.com/tuanminhhole/openclaw-setup/main/docs/dashboard.png" alt="OpenClaw Dashboard" width="49%" style="border-radius: 8px; border: 1px solid #333;" />
22
- </p>
23
-
24
- </div>
25
-
26
- ---
27
-
28
- ## 🆕 mới trong v5.8.0 (Bản nâng cấp lớn)
29
-
30
- - 🎨 **Giao diện Quản trị Web UI Mới**: Thay thế hoàn toàn các file tĩnh `index.html` kịch bản dòng lệnh thủ công bằng một Dashboard cài đặt quản bot cực kỳ trực quan với tone màu Dark Red/Black cao cấp.
31
- - 🔀 **Hợp nhất Cấu hình AI qua 9Router**: Từ phiên bản này, trình cài đặt tối giản hóa bằng việc sử dụng duy nhất **9Router** làm Gateway AI Proxy trung tâm. Người dùng không cần cấu hình API key phức tạp hay thủ công cho từng provider nữa. Thông qua 9Router, bạn có thể dễ dàng quản lý và kết nối mọi nhà cung cấp AI từ miễn phí (như Google Gemini free tier, Ollama local chạy offline) đến các hình trả phí cao cấp (như OpenAI GPT-4o, Anthropic Claude...) thông qua một giao diện đăng nhập OAuth cực kỳ nhanh chóng và bảo mật.
32
- - 📊 **Bảng điều khiển Tiến trình (Process Controller)**: Dễ dàng Bật (`Start`), Tắt (`Stop`), hoặc Tạo lại (`Recreate`) các bot container ngay trên giao diện Web không cần bất cứ lệnh Docker nào.
33
- - 📑 **Xem Log thời gian thực (Live Logs)**: Tích hợp trình xem nhật hoạt động trực tiếp (streaming logs) từ bot lên giao diện, hỗ trợ tối đa cho việc kiểm tra và khắc phục lỗi tức thì.
34
- - 📁 **Trình quản File trực quan (File Tree Editor)**: Cho phép xemchỉnh sửa trực tiếp các file cấu hình quan trọng như `openclaw.json`, `SOUL.md`, `AGENTS.md` ngay từ trình duyệt web.
35
- - 🔑 **Đăng nhập Zalo QR trực tiếp**: Tích hợp luồng kích hoạt Zalo Personal bằng cách quét mã QR hiển thị ngay trên giao diện quản trị.
36
- - 🔄 **Phân bổ Cổng Mạng thông minh**: Cơ chế tự động phát hiện cổng rảnh và gán cổng động (`routerPort`) giúp loại bỏ hoàn toàn xung đột mạng khi chạy nhiều bot trên cùng một máy.
37
-
38
- ---
39
-
40
- ## Tính năng nổi bật
41
-
42
- - 🤖 **Đa kênh** — Telegram (1 hoặc nhiều bot), Zalo Bot API, hoặc Zalo Personal ( nhân).
43
- - 🧑‍🤝‍🧑 **Đội bot (Multi-bot Team)** — Chạy đồng thời nhiều bot Telegram/Zalo, tự động đồng bộ hóa tài liệu phối hợp làm việc theo nhóm.
44
- - 🧠 **Đa nhà cung cấp AI qua 9Router** Dễ dàng định tuyến đến Google Gemini, Claude, GPT-4o, OpenRouter, Ollama (chạy local offline).
45
- - 🧩 **Kỹ năng (Skills)** — Web Search, Browser Automation (Chrome CDP thực tế), Cron/Scheduler lập lịch.
46
- - 🔌 **Plugin tích hợp** Cài đặt nhanh các plugin nâng cao (`openclaw-zalo-mod`, Facebook Crawler...) chỉ bằng 1 nút nhấn trên UI.
47
- - 🔀 **9Router tích hợp** — Cầu nối AI proxy miễn phí không cần API key thông qua đăng nhập OAuth.
48
- - 🔒 **An toàn & Riêng tư** — Toàn bộ cấu hình và API key chỉ lưu trên thiết bị của bạn.
49
-
50
- ---
51
-
52
- ## 🗺️ Cách cài đặt nhanh nhất
53
-
54
- ### 1️⃣ Cách 1: Sử dụng NPX (Không cần tải code trước)
55
-
56
- Mở terminal trên máy của bạn và chạy lệnh duy nhất:
57
-
58
- ```bash
59
- npx create-openclaw-bot
60
- ```
61
-
62
- _Hệ thống sẽ tự động tạo thư mục, cài đặt môi trường và mở giao diện Web Setup trên trình duyệt._
63
-
64
- ### 2️⃣ Cách 2: Clone thủ công
65
-
66
- Nếu bạn tải mã nguồn từ GitHub về máy:
67
-
68
- ```bash
69
- npm install
70
- npm start
71
- ```
72
-
73
- ---
74
-
75
- ## 📋 Yêu cầu hệ thống
76
-
77
- - **Node.js**: Phiên bản 20, 22 hoặc 24 (Tránh dùng bản Node.js 25 do xung đột runtime).
78
- - **Git**: Đã cài đặt và có trong biến môi trường PATH.
79
- - **Docker Desktop** (Nếu chọn cài đặt qua Docker): Hỗ trợ Docker Compose V2.
80
-
81
- ---
82
-
83
- ## 🧠 Các Provider AI được hỗ trợ (Thông qua 9Router)
84
-
85
- - [9Router GitHub](https://github.com/decolua/9router)
86
-
87
- ---
88
-
89
- ## 🔌 Kênh trò chuyện hỗ trợ
90
-
91
- - **Telegram**: Lấy token bot chính thức từ `@BotFather`.
92
- - **Zalo Bot API**: Lấy thông tin kết nối chính thức từ [developers.zalo.me](https://developers.zalo.me).
93
- - **Zalo Cá nhân (Zalo Personal)**: Kích hoạt cực nhanh bằng cách quét mã QR hiển thị ngay trên Dashboard OpenClaw.
94
-
95
- ---
96
-
97
- ## 📁 Cấu trúc thư mục dự án
98
-
99
- ```text
100
- openclaw-setup/
101
- |-- README.md Tài liệu tiếng Anh
102
- |-- README.vi.md Hướng dẫn tiếng Việt (Bạn đang đọc)
103
- |-- package.json Điểm cấu hình NPM scripts khởi chạy
104
- |-- dist/ ← Mã nguồn đã biên dịch của Web UI và CLI
105
- `-- src/ ← Mã nguồn gốc (giao diện, máy chủ cục bộ API, script build)
106
- ```
107
-
108
- ---
109
-
110
- ## ❓ Câu hỏi thường gặp
111
-
112
- <details>
113
- <summary><b>Làm thế nào để dừng hoặc chạy lại bot?</b></summary>
114
- Giờ đây bạn không cần gõ lệnh nữa! Chỉ cần mở Web UI Setup lên, truy cập tab <b>Bot</b> và sử dụng nút bấm <b>Start / Stop / Recreate</b> để quản lý trực quan tiến trình hoạt động của Bot.
115
- </details>
116
-
117
- <details>
118
- <summary><b>Sửa tính cách bot và danh sách tác vụ ở đâu?</b></summary>
119
- Bạn có thể sửa trực tiếp ngay trên trình duyệt bằng cách truy cập tab <b>Bot</b>, cuộn xuống phần <b>Bot file tree</b> và click chọn file cần sửa (ví dụ: `SOUL.md`, `AGENTS.md`). Sau khi sửa xong nhấn <b>Save</b> là cấu hình sẽ được cập nhật ngay lập tức.
120
- </details>
121
-
122
- <details>
123
- <summary><b>Tôi có thể đổi model AI sau khi cài không?</b></summary>
124
- Hoàn toàn được. Bạn có thể sửa trực tiếp file `openclaw.json` ở giao diện web của setup, hoặc chạy lại lệnh cài đặt trỏ vào thư mục cũ để cập nhật nhanh cấu hình.
125
- </details>
126
-
127
- ---
128
-
129
- ## 🔗 Liên kết hữu ích
130
-
131
- - [OpenClaw Docs](https://openclaw.ai/docs)
132
- - [9Router GitHub](https://github.com/decolua/9router)
133
- - [Google AI Studio](https://aistudio.google.com/)
134
- - [Telegram BotFather](https://t.me/BotFather)
135
- - [Zalo Developer Platform](https://developers.zalo.me)
136
- - [Docker Desktop](https://www.docker.com/products/docker-desktop/)
137
- - [ClawHub (Skills)](https://clawhub.com)
138
-
139
- ---
140
-
141
- ## 📈 Star History
142
-
143
- <div align="center">
144
-
145
- [![Star History Chart](https://starchart.cc/tuanminhhole/openclaw-setup.svg?variant=adaptive)](https://starchart.cc/tuanminhhole/openclaw-setup)
146
-
147
- </div>
148
-
149
- ---
150
-
151
- ## 🙏 Lời cảm ơn
152
-
153
- - [OpenClaw](https://openclaw.ai) — AI Gateway framework
154
- - [9Router](https://github.com/decolua/9router) — Open-source AI proxy (OAuth-based, no API keys)
155
- - [ClawHub](https://clawhub.com) — Kho đăng ký các kỹ năng của bot
156
- - [TheSVG](https://thesvg.org) — Kho biểu tượng nhãn hiệu SVG chất lượng cao
157
-
158
- ---
159
-
160
- <div align="center">
161
-
162
- Made with 🦞 by [Kent](https://github.com/tuanminhhole)
163
-
164
- </div>
1
+ <div align="center">
2
+
3
+ # 🦞 OpenClaw Setup
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/tuanminhhole/openclaw-setup/releases"><img src="https://img.shields.io/badge/RELEASE-v5.8.0-0EA5E9?style=for-the-badge" alt="Version 5.8.0" /></a>
7
+ <a href="https://github.com/tuanminhhole/openclaw-setup?tab=MIT-1-ov-file"><img src="https://img.shields.io/badge/LICENSE-MIT-success?style=for-the-badge" alt="MIT License" /></a>
8
+ <a href="https://www.npmjs.com/package/create-openclaw-bot"><img src="https://img.shields.io/npm/v/create-openclaw-bot?style=for-the-badge&label=CLI&color=2563EB&logo=npm&logoColor=white" alt="NPM Version" /></a>
9
+ <a href="https://github.com/tuanminhhole/openclaw-setup/stargazers"><img src="https://img.shields.io/github/stars/tuanminhhole/openclaw-setup?style=for-the-badge&color=eab308&logo=github&logoColor=white" alt="GitHub Stars" /></a>
10
+ </p>
11
+
12
+ ![Tiếng Việt](https://flagcdn.com/20x15/vn.png) **Tiếng Việt** · [![English](https://flagcdn.com/20x15/gb.png) English](README.md)
13
+
14
+ Trình cài đặt quản trị **Web UI Setup** thế hệ mới giúp tự động hóa 100% quá trình tạo dự án, triển khai và quản lý đa bot AI miễn phí trên Telegram hoặc Zalo — hỗ trợ **Windows, macOS, Ubuntu, VPS**.
15
+
16
+ <p align="center" style="margin: 24px 0;">
17
+ <img src="https://raw.githubusercontent.com/tuanminhhole/openclaw-setup/main/docs/openclaw-setup-vi.png" alt="OpenClaw Setup" width="90%" style="border-radius: 8px; border: 1px solid #333; margin-bottom: 16px;" />
18
+ <img src="https://raw.githubusercontent.com/tuanminhhole/openclaw-setup/main/docs/dashboard-vi.png" alt="OpenClaw Dashboard" width="90%" style="border-radius: 8px; border: 1px solid #333; margin-bottom: 16px;" />
19
+ <img src="https://raw.githubusercontent.com/tuanminhhole/openclaw-setup/main/docs/bot.png" alt="OpenClaw Bot in Action" width="90%" style="border-radius: 8px; border: 1px solid #333;" />
20
+ </p>
21
+
22
+ </div>
23
+
24
+ ---
25
+
26
+ ## 🆕 Có gì mới trong v5.8.0 (Bản nâng cấp lớn)
27
+
28
+ - 🎨 **Giao diện Quản trị Web UI Mới**: Thay thế hoàn toàn các file tĩnh `index.html` kịch bản dòng lệnh thủ công bằng một Dashboard cài đặt và quản lý bot cực kỳ trực quan với tone màu Dark Red/Black cao cấp.
29
+ - 🔀 **Hợp nhất Cấu hình AI qua 9Router**: Từ phiên bản này, trình cài đặt tối giản hóa bằng việc sử dụng duy nhất **9Router** làm Gateway AI Proxy trung tâm. Người dùng không cần cấu hình API key phức tạp hay thủ công cho từng provider nữa. Thông qua 9Router, bạn có thể dễ dàng quản lý và kết nối mọi nhà cung cấp AI từ miễn phí (như Google Gemini free tier, Ollama local chạy offline) đến các mô hình trả phí cao cấp (như OpenAI GPT-4o, Anthropic Claude...) thông qua một giao diện đăng nhập OAuth cực kỳ nhanh chóng và bảo mật.
30
+ - 📊 **Bảng điều khiển Tiến trình (Process Controller)**: Dễ dàng Bật (`Start`), Tắt (`Stop`), hoặc Tạo lại (`Recreate`) các bot container ngay trên giao diện Web không cần bất cứ lệnh Docker nào.
31
+ - 📑 **Xem Log thời gian thực (Live Logs)**: Tích hợp trình xem nhật hoạt động trực tiếp (streaming logs) từ bot lên giao diện, hỗ trợ tối đa cho việc kiểm tra khắc phục lỗi tức thì.
32
+ - 📁 **Trình quản File trực quan (File Tree Editor)**: Cho phép xem chỉnh sửa trực tiếp các file cấu hình quan trọng như `openclaw.json`, `SOUL.md`, `AGENTS.md` ngay từ trình duyệt web.
33
+ - 🔑 **Đăng nhập Zalo QR trực tiếp**: Tích hợp luồng kích hoạt Zalo Personal bằng cách quét QR hiển thị ngay trên giao diện quản trị.
34
+ - 🔄 **Phân bổ Cổng Mạng thông minh**: chế tự động phát hiện cổng rảnh gán cổng động (`routerPort`) giúp loại bỏ hoàn toàn xung đột mạng khi chạy nhiều bot trên cùng một máy.
35
+
36
+ ---
37
+
38
+ ## ✨ Tính năng nổi bật
39
+
40
+ - 🤖 **Đa kênh** Telegram (1 hoặc nhiều bot), Zalo Bot API, hoặc Zalo Personal (Cá nhân).
41
+ - 🧑‍🤝‍🧑 **Đội bot (Multi-bot Team)** — Chạy đồng thời nhiều bot Telegram/Zalo, tự động đồng bộ hóa tài liệu và phối hợp làm việc theo nhóm.
42
+ - 🧠 **Đa nhà cung cấp AI qua 9Router** — Dễ dàng định tuyến đến Google Gemini, Claude, GPT-4o, OpenRouter, Ollama (chạy local offline).
43
+ - 🧩 **Kỹ năng (Skills)** — Web Search, Browser Automation (Chrome CDP thực tế), Cron/Scheduler lập lịch.
44
+ - 🔌 **Plugin tích hợp** Cài đặt nhanh các plugin nâng cao (`openclaw-zalo-mod`, Facebook Crawler...) chỉ bằng 1 nút nhấn trên UI.
45
+ - 🔀 **9Router tích hợp** — Cầu nối AI proxy miễn phí không cần API key thông qua đăng nhập OAuth.
46
+ - 🔒 **An toàn & Riêng tư** Toàn bộ cấu hình API key chỉ lưu trên thiết bị của bạn.
47
+
48
+ ---
49
+
50
+ ## 🗺️ Cách cài đặt nhanh nhất
51
+
52
+ ### 1️⃣ Cách 1: Sử dụng NPX (Không cần tải code trước)
53
+
54
+ Mở terminal trên máy của bạn chạy lệnh duy nhất:
55
+
56
+ ```bash
57
+ npx create-openclaw-bot
58
+ ```
59
+
60
+ _Hệ thống sẽ tự động tạo thư mục, cài đặt môi trường và mở giao diện Web Setup trên trình duyệt._
61
+
62
+ ### 2️⃣ Cách 2: Clone thủ công
63
+
64
+ Nếu bạn tải nguồn từ GitHub về máy:
65
+
66
+ ```bash
67
+ npm install
68
+ npm start
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 📋 Yêu cầu hệ thống
74
+
75
+ - **Node.js**: Phiên bản 20, 22 hoặc 24 (Tránh dùng bản Node.js 25 do xung đột runtime).
76
+ - **Git**: Đã cài đặt và có trong biến môi trường PATH.
77
+ - **Docker Desktop** (Nếu chọn cài đặt qua Docker): Hỗ trợ Docker Compose V2.
78
+
79
+ ---
80
+
81
+ ## 🧠 Các Provider AI được hỗ trợ (Thông qua 9Router)
82
+
83
+ - [9Router GitHub](https://github.com/decolua/9router)
84
+
85
+ ---
86
+
87
+ ## 🔌 Kênh trò chuyện hỗ trợ
88
+
89
+ - **Telegram**: Lấy token bot chính thức từ `@BotFather`.
90
+ - **Zalo Bot API**: Lấy thông tin kết nối chính thức từ [developers.zalo.me](https://developers.zalo.me).
91
+ - **Zalo Cá nhân (Zalo Personal)**: Kích hoạt cực nhanh bằng cách quét mã QR hiển thị ngay trên Dashboard OpenClaw.
92
+
93
+ ---
94
+
95
+ ## 📁 Cấu trúc thư mục dự án
96
+
97
+ ```text
98
+ openclaw-setup/
99
+ |-- README.md ← Tài liệu tiếng Anh
100
+ |-- README.vi.md ← Hướng dẫn tiếng Việt (Bạn đang đọc)
101
+ |-- package.json Điểm cấu hình NPM và scripts khởi chạy
102
+ |-- dist/ nguồn đã biên dịch của Web UI và CLI
103
+ `-- src/ nguồn gốc (giao diện, máy chủ cục bộ API, script build)
104
+ ```
105
+
106
+ ---
107
+
108
+ ## ❓ Câu hỏi thường gặp
109
+
110
+ <details>
111
+ <summary><b>Làm thế nào để dừng hoặc chạy lại bot?</b></summary>
112
+ Giờ đây bạn không cần gõ lệnh nữa! Chỉ cần mở Web UI Setup lên, truy cập tab <b>Bot</b> và sử dụng nút bấm <b>Start / Stop / Recreate</b> để quản lý trực quan tiến trình hoạt động của Bot.
113
+ </details>
114
+
115
+ <details>
116
+ <summary><b>Sửa tính cách bot và danh sách tác vụ ở đâu?</b></summary>
117
+ Bạn có thể sửa trực tiếp ngay trên trình duyệt bằng cách truy cập tab <b>Bot</b>, cuộn xuống phần <b>Bot file tree</b> và click chọn file cần sửa (ví dụ: `SOUL.md`, `AGENTS.md`). Sau khi sửa xong nhấn <b>Save</b> là cấu hình sẽ được cập nhật ngay lập tức.
118
+ </details>
119
+
120
+ <details>
121
+ <summary><b>Tôi có thể đổi model AI sau khi cài không?</b></summary>
122
+ Hoàn toàn được. Bạn có thể sửa trực tiếp file `openclaw.json` ở giao diện web của setup, hoặc chạy lại lệnh cài đặt trỏ vào thư mục cũ để cập nhật nhanh cấu hình.
123
+ </details>
124
+
125
+ ---
126
+
127
+ ## 🔗 Liên kết hữu ích
128
+
129
+ - [OpenClaw Docs](https://openclaw.ai/docs)
130
+ - [9Router GitHub](https://github.com/decolua/9router)
131
+ - [Google AI Studio](https://aistudio.google.com/)
132
+ - [Telegram BotFather](https://t.me/BotFather)
133
+ - [Zalo Developer Platform](https://developers.zalo.me)
134
+ - [Docker Desktop](https://www.docker.com/products/docker-desktop/)
135
+ - [ClawHub (Skills)](https://clawhub.com)
136
+
137
+ ---
138
+
139
+ ## 📈 Star History
140
+
141
+ <div align="center">
142
+
143
+ [![Star History Chart](https://starchart.cc/tuanminhhole/openclaw-setup.svg?variant=adaptive)](https://starchart.cc/tuanminhhole/openclaw-setup)
144
+
145
+ </div>
146
+
147
+ ---
148
+
149
+ ## 🙏 Lời cảm ơn
150
+
151
+ - [OpenClaw](https://openclaw.ai) AI Gateway framework
152
+ - [9Router](https://github.com/decolua/9router) — Open-source AI proxy (OAuth-based, no API keys)
153
+ - [ClawHub](https://clawhub.com) — Kho đăng ký các kỹ năng của bot
154
+ - [TheSVG](https://thesvg.org) — Kho biểu tượng nhãn hiệu SVG chất lượng cao
155
+
156
+ ---
157
+
158
+ <div align="center">
159
+
160
+ Made with 🦞 by [Kent](https://github.com/tuanminhhole)
161
+
162
+ </div>
package/dist/cli.js CHANGED
@@ -1,112 +1,125 @@
1
- #!/usr/bin/env node
2
- import { spawn } from 'child_process';
3
- import fs from 'fs';
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- function isLocalRepo() {
11
- const pathsToTry = [
12
- path.resolve(__dirname, '..'),
13
- path.resolve(__dirname, '../..')
14
- ];
15
- for (const rootDir of pathsToTry) {
16
- const pkgPath = path.join(rootDir, 'package.json');
17
- if (fs.existsSync(pkgPath)) {
18
- try {
19
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
20
- if (pkg.name === 'create-openclaw-bot' && fs.existsSync(path.join(rootDir, 'src', 'cli', 'cli.src.js'))) {
21
- return true;
22
- }
23
- } catch {}
24
- }
25
- }
26
- return false;
27
- }
28
-
29
- const args = process.argv.slice(2);
30
-
31
- if (isLocalRepo()) {
32
- const { startLocalInstaller } = await import('./server/local-server.js');
33
-
34
- if (args[0] === 'legacy' || args.includes('--legacy')) {
35
- await import('./legacy-cli.js');
36
- } else {
37
- const noOpen = args.includes('--no-open');
38
- const hostArg = args.find((arg) => arg.startsWith('--host='));
39
- const portArg = args.find((arg) => arg.startsWith('--port='));
40
- const projectDirArg = args.find((arg) => arg.startsWith('--project-dir='));
41
-
42
- await startLocalInstaller({
43
- openBrowser: !noOpen,
44
- host: hostArg ? hostArg.slice('--host='.length) : '127.0.0.1',
45
- preferredPort: portArg ? Number(portArg.slice('--port='.length)) : 51789,
46
- projectDir: projectDirArg ? projectDirArg.slice('--project-dir='.length) : process.cwd(),
47
- });
48
- }
49
- } else {
50
- console.log('\n============================================================');
51
- console.log(' 🦞 OpenClaw Setup — Auto-downloader & Installer');
52
- console.log('============================================================\n');
53
-
54
- const targetDirName = 'openclaw-setup';
55
- const targetPath = path.join(process.cwd(), targetDirName);
56
-
57
- const runCmd = (cmd, cmdArgs, opts = {}) => {
58
- return new Promise((resolve, reject) => {
59
- const child = spawn(cmd, cmdArgs, {
60
- shell: true,
61
- stdio: 'inherit',
62
- ...opts
63
- });
64
- child.on('close', (code) => {
65
- if (code === 0) resolve();
66
- else reject(new Error(`${cmd} exited with code ${code}`));
67
- });
68
- child.on('error', reject);
69
- });
70
- };
71
-
72
- try {
73
- // Check if git is installed
74
- try {
75
- await new Promise((resolve, reject) => {
76
- const child = spawn('git', ['--version'], { shell: true, stdio: 'ignore' });
77
- child.on('close', (code) => {
78
- if (code === 0) resolve();
79
- else reject(new Error());
80
- });
81
- child.on('error', reject);
82
- });
83
- } catch {
84
- throw new Error('Git is not installed or not found in PATH. Please install Git and try again.');
85
- }
86
-
87
- if (!fs.existsSync(targetPath)) {
88
- console.log(`[1/3] Cloning OpenClaw setup repository to: ${targetPath}...`);
89
- await runCmd('git', ['clone', 'https://github.com/tuanminhhole/openclaw-setup.git', targetDirName]);
90
- } else {
91
- console.log(`[1/3] OpenClaw setup folder already exists at: ${targetPath}`);
92
- console.log(' Updating repository to latest version...');
93
- try {
94
- await runCmd('git', ['pull'], { cwd: targetPath });
95
- } catch (err) {
96
- console.warn(' Warning: Failed to git pull (continuing anyway):', err.message);
97
- }
98
- }
99
-
100
- console.log('\n[2/3] Installing dependencies...');
101
- await runCmd('npm', ['install'], { cwd: targetPath });
102
-
103
- console.log('\n[3/3] Starting OpenClaw Setup UI...');
104
- const originalCwd = process.cwd();
105
- const cliPath = path.join('dist', 'cli.js');
106
- await runCmd('node', [cliPath, ...args, `--project-dir=${originalCwd}`], { cwd: targetPath });
107
-
108
- } catch (error) {
109
- console.error('\n❌ Error during setup:', error.message);
110
- process.exit(1);
111
- }
112
- }
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'child_process';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import os from 'os';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ function isLocalRepo() {
12
+ const pathsToTry = [
13
+ path.resolve(__dirname, '..'),
14
+ path.resolve(__dirname, '../..')
15
+ ];
16
+ for (const rootDir of pathsToTry) {
17
+ const pkgPath = path.join(rootDir, 'package.json');
18
+ if (fs.existsSync(pkgPath)) {
19
+ try {
20
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
21
+ if (pkg.name === 'create-openclaw-bot' && fs.existsSync(path.join(rootDir, 'src', 'cli', 'cli.src.js'))) {
22
+ return true;
23
+ }
24
+ } catch {}
25
+ }
26
+ }
27
+ return false;
28
+ }
29
+
30
+ const args = process.argv.slice(2);
31
+
32
+ if (isLocalRepo()) {
33
+ const { startLocalInstaller } = await import('./server/local-server.js');
34
+
35
+ if (args[0] === 'legacy' || args.includes('--legacy')) {
36
+ await import('./legacy-cli.js');
37
+ } else {
38
+ const noOpen = args.includes('--no-open');
39
+ const hostArg = args.find((arg) => arg.startsWith('--host='));
40
+ const portArg = args.find((arg) => arg.startsWith('--port='));
41
+ const projectDirArg = args.find((arg) => arg.startsWith('--project-dir='));
42
+
43
+ await startLocalInstaller({
44
+ openBrowser: !noOpen,
45
+ host: hostArg ? hostArg.slice('--host='.length) : '127.0.0.1',
46
+ preferredPort: portArg ? Number(portArg.slice('--port='.length)) : 51789,
47
+ projectDir: projectDirArg ? projectDirArg.slice('--project-dir='.length) : process.cwd(),
48
+ });
49
+ }
50
+ } else {
51
+ console.log('\n============================================================');
52
+ console.log(' 🦞 OpenClaw Setup — Auto-downloader & Installer');
53
+ console.log('============================================================\n');
54
+
55
+ const targetDirName = '.openclaw-setup';
56
+ const targetPath = path.join(os.homedir(), targetDirName);
57
+
58
+ const runCmd = (cmd, cmdArgs, opts = {}) => {
59
+ return new Promise((resolve, reject) => {
60
+ const child = spawn(cmd, cmdArgs, {
61
+ shell: true,
62
+ stdio: 'inherit',
63
+ ...opts
64
+ });
65
+ child.on('close', (code) => {
66
+ if (code === 0) resolve();
67
+ else reject(new Error(`${cmd} exited with code ${code}`));
68
+ });
69
+ child.on('error', reject);
70
+ });
71
+ };
72
+
73
+ try {
74
+ // Check if git is installed
75
+ try {
76
+ await new Promise((resolve, reject) => {
77
+ const child = spawn('git', ['--version'], { shell: true, stdio: 'ignore' });
78
+ child.on('close', (code) => {
79
+ if (code === 0) resolve();
80
+ else reject(new Error());
81
+ });
82
+ child.on('error', reject);
83
+ });
84
+ } catch {
85
+ throw new Error('Git is not installed or not found in PATH. Please install Git and try again.');
86
+ }
87
+
88
+ const isGitRepo = fs.existsSync(path.join(targetPath, '.git'));
89
+ const hasPackageJson = fs.existsSync(path.join(targetPath, 'package.json'));
90
+
91
+ if (!fs.existsSync(targetPath) || !isGitRepo || !hasPackageJson) {
92
+ if (fs.existsSync(targetPath)) {
93
+ console.log(`⚠️ Thư mục cài đặt UI tồn tại ở ${targetPath} nhưng bị lỗi hoặc thiếu tệp (.git / package.json).`);
94
+ console.log(' Đang dọn dẹp thư mục UI ẩn để tiến hành tải mới hoàn toàn...');
95
+ try {
96
+ fs.rmSync(targetPath, { recursive: true, force: true });
97
+ } catch (rmErr) {
98
+ console.warn(' Cảnh báo: Không thể xóa thư mục, sẽ thử tải đè:', rmErr.message);
99
+ }
100
+ }
101
+ console.log(`[1/3] Cloning OpenClaw setup repository to: ${targetPath}...`);
102
+ await runCmd('git', ['clone', 'https://github.com/tuanminhhole/openclaw-setup.git', targetPath]);
103
+ } else {
104
+ console.log(`[1/3] OpenClaw setup folder already exists at: ${targetPath}`);
105
+ console.log(' Updating repository to latest version...');
106
+ try {
107
+ await runCmd('git', ['pull'], { cwd: targetPath });
108
+ } catch (err) {
109
+ console.warn(' Warning: Failed to git pull (continuing anyway):', err.message);
110
+ }
111
+ }
112
+
113
+ console.log('\n[2/3] Installing dependencies...');
114
+ await runCmd('npm', ['install'], { cwd: targetPath });
115
+
116
+ console.log('\n[3/3] Starting OpenClaw Setup UI...');
117
+ const originalCwd = process.cwd();
118
+ const cliPath = path.join('dist', 'cli.js');
119
+ await runCmd('node', [cliPath, ...args, `--project-dir=${originalCwd}`], { cwd: targetPath });
120
+
121
+ } catch (error) {
122
+ console.error('\n❌ Error during setup:', error.message);
123
+ process.exit(1);
124
+ }
125
+ }