@quangnv13/nonstop 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.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # 🚀 nonstop
2
+
3
+ 🌐 [Tiếng Việt](./README.vi.md) | **English**
4
+
5
+ <p align="center">
6
+ <img src="./images/nonstop.png" alt="nonstop Banner" width="800px" style="border-radius: 8px;" />
7
+ </p>
8
+
9
+ [![TypeScript](https://img.shields.io/badge/Language-TypeScript-blue.svg)](https://www.typescriptlang.org/)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-brightgreen.svg)]()
12
+
13
+ `nonstop` is a terminal control center and background runner for a local, Telegram-driven PTY runtime. It provides a robust root-level CLI/TUI for system management, config tuning, workspace mapping, and OS startup integration, while the Telegram bot securely delegates PTY sessions (PowerShell, Bash, etc.) in the background.
14
+
15
+ ---
16
+
17
+ ## 🌟 Key Features
18
+
19
+ * **💻 Immersive TUI Control Center** — Manage runtime processes, inspect logs, register workspaces, and edit configuration directly from a command-line interface.
20
+ * **🤖 Telegram PTY Terminal** — Execute and control real-time, interactive shell sessions (PowerShell, Bash, Codex, or Antigravity) remotely from Telegram.
21
+ * **⚙️ Inline Configuration Engine** — Modify environment settings dynamically through the new `/config` inline Telegram menu or directly in the CLI.
22
+ * **📂 Smart Workspaces** — Navigate and switch between different working directories on your machine with a few taps.
23
+ * **🔄 Optimized Output Stream** — Advanced batch-delivery mechanics with configurable output intervals, ensuring fluid terminal logs inside Telegram without hitting API limits.
24
+ * **🚀 Native OS Autostart** — Easy configuration to run as a background service on OS startup (supports Windows and Linux).
25
+ * **🌐 Bilingual Support** — Fully localized in English (`en`) and Vietnamese (`vi`).
26
+ * **🛡️ Hardened Security** — Hardened token validation and authorization checks, restricting control access strictly to the configured admin account.
27
+
28
+ ---
29
+
30
+ ## ⚙️ Architecture & Data Flow
31
+
32
+ ```mermaid
33
+ graph TD
34
+ TelegramUser[📱 Telegram Client] <-->|Secure API Messages| TelegramServer[☁️ Telegram Bot API]
35
+ TelegramServer <-->|Grammy Framework| BotRuntime[🤖 Bot Runtime Process]
36
+
37
+ subgraph Local Server Environment
38
+ BotRuntime <-->|node-pty| PTY[💻 PTY Session <br> PowerShell / Bash / Codex]
39
+ BotRuntime <-->|Manage / Query| RuntimeState[📁 data/ & .env]
40
+
41
+ TUI[💻 Nonstop TUI Control Center] <-->|Read / Write| RuntimeState
42
+ TUI <-->|Control Daemon| BotRuntime
43
+ end
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 🕹️ Usage Guide
49
+
50
+ ### 1. Local TUI Control Center
51
+ Run `npm start` (or `npm run dev`) to open the terminal management dashboard. From here, you can:
52
+ * **Start / Stop** the background bot runtime.
53
+ * **Configure Workspaces**: Manage directories where terminal sessions can be started.
54
+ * **Autostart Settings**: Set up the application to run automatically on system boot.
55
+ * **View Logs**: Monitor bot logs and output in real time.
56
+
57
+ ### 2. Telegram Bot Interaction
58
+ Once the bot runtime is active, you can interact with it via the following Telegram interface commands:
59
+
60
+ #### **📜 Commands**
61
+ * `/start` — Bring up the main interactive menu.
62
+ * `/status` — View current runtime health (active workspaces, running sessions, presets).
63
+ * `/config` — Edit application parameters dynamically.
64
+ * `/send <command>` — Send raw input directly to the active session.
65
+ * `/help` — Display bot commands and help text.
66
+
67
+ #### **⚡ Managing PTY Shell Sessions**
68
+ 1. Select **⚡ Session** from the main menu.
69
+ 2. Select an environment preset (e.g., **PowerShell**, **Bash**, **Codex**, or **Antigravity**) to start a session.
70
+ 3. Once running, **enable Input Mode**.
71
+ 4. Any normal text message you send to the bot (without a leading `/`) will be fed directly into your shell.
72
+ 5. Use the inline control buttons to send key inputs:
73
+ * **⛔ Esc** — Send the Escape key to interrupt/cancel processes.
74
+ * **⏎ Enter** — Send a carriage return.
75
+ * **▲ Up / ▼ Down** — Navigate command history.
76
+
77
+ #### **📂 Directory Workspaces**
78
+ * Select **📁 Workspaces** from the main menu to view the folders configured in `data/workspaces.json`.
79
+ * Selecting a workspace sets it as the working directory for your next PTY session.
80
+
81
+ #### **⚙️ Dynamic Configuration**
82
+ * Press **⚙️ Cấu hình** or send `/config`.
83
+ * Tap any settings button (e.g. *Token*, *Admin*, *Interval*, etc.) and send a new value via message to apply immediately.
84
+ * If you modify the `Telegram Bot Token`, the bot will automatically reload and restart itself securely.
85
+
86
+ ---
87
+
88
+ ## 🛠️ Quick Start
89
+
90
+ ### 1. Prerequisites
91
+ Ensure you have [Node.js](https://nodejs.org/) (v18+) and `npm` installed.
92
+
93
+ ### 2. Installation
94
+ Clone the repository and install the dependencies:
95
+ ```bash
96
+ git clone https://github.com/quangnv13/nonstop.git
97
+ cd nonstop
98
+ npm install
99
+ ```
100
+
101
+ ### 3. Build the Application
102
+ Compile TypeScript to JavaScript production files:
103
+ ```bash
104
+ npm run build
105
+ ```
106
+
107
+ ### 4. Run `nonstop`
108
+ Launch the interactive terminal-based Control Center:
109
+ ```bash
110
+ npm start
111
+ ```
112
+ > [!NOTE]
113
+ > On the first launch, if your `.env` configuration file is missing, `nonstop` will automatically trigger a **Setup Wizard** to configure your Telegram bot token, allowed admin username, client name, language, and startup settings.
114
+
115
+ For development mode (with hot-reload):
116
+ ```bash
117
+ npm run dev
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 📁 Repository Layout
123
+
124
+ ```text
125
+ nonstop/
126
+ ├── data/ # Persistent storage (logs, workspaces.json, last-chat-id)
127
+ ├── src/ # TypeScript source files
128
+ │ ├── bot.ts # Telegram bot handlers & callback commands
129
+ │ ├── config.ts # Config parsers, disk storage, and env bindings
130
+ │ ├── runtime.ts # Shell session controls & PTY managers
131
+ │ ├── ui.ts # TUI Control Center console interface
132
+ │ └── index.ts # App bootstrapper
133
+ ├── dist/ # Compiled JavaScript files
134
+ ├── .env # Runtime environment file (git-ignored)
135
+ └── package.json # Node manifest & scripts
136
+ ```
137
+
138
+ ---
139
+
140
+ ## 🎛️ Configuration
141
+
142
+ Configuration is managed via `.env` at the root of the project. You can copy the template from [`.env.example`](.env.example):
143
+
144
+ ```ini
145
+ TELEGRAM_BOT_TOKEN=your_telegram_bot_token
146
+ ADMIN_USERNAME=@your_telegram_username
147
+ TELEGRAM_USERNAME=@your_telegram_username
148
+ CLIENT_NAME=nonstop-local
149
+ APP_LANGUAGE=en
150
+ STARTUP_MODE=disabled
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 🛡️ Security Best Practices
156
+
157
+ > [!WARNING]
158
+ > Because `nonstop` exposes your machine's shell environments remotely over Telegram, please observe the following security precautions:
159
+ >
160
+ > 1. **Keep Your Token Secret**: Never commit your `.env` or share your `TELEGRAM_BOT_TOKEN`.
161
+ > 2. **Double Check Admin Username**: Ensure `ADMIN_USERNAME` is spelled correctly (include the `@` prefix) to prevent unauthorized access.
162
+ > 3. **Least Privilege Principle**: Avoid running the `nonstop` process under highly privileged accounts (like Administrator or root) unless absolutely required.
163
+
164
+ ---
165
+
166
+ ## 📄 License
167
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
package/README.vi.md ADDED
@@ -0,0 +1,167 @@
1
+ # 🚀 nonstop
2
+
3
+ 🌐 **Tiếng Việt** | [English](./README.md)
4
+
5
+ <p align="center">
6
+ <img src="./images/nonstop.png" alt="nonstop Banner" width="800px" style="border-radius: 8px;" />
7
+ </p>
8
+
9
+ [![TypeScript](https://img.shields.io/badge/Language-TypeScript-blue.svg)](https://www.typescriptlang.org/)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20Linux-brightgreen.svg)]()
12
+
13
+ `nonstop` là trung tâm điều khiển terminal và tiến trình chạy ẩn cho môi trường PTY cục bộ được điều khiển qua Telegram. Dự án cung cấp giao diện CLI/TUI mạnh mẽ ở cấp root để quản lý hệ thống, tùy chỉnh cấu hình, lập bản đồ thư mục làm việc (workspaces), tích hợp khởi động cùng hệ điều hành, trong khi bot Telegram chạy ẩn thực thi và điều phối các phiên PTY (PowerShell, Bash, v.v.) một cách bảo mật.
14
+
15
+ ---
16
+
17
+ ## 🌟 Tính Năng Nổi Bật
18
+
19
+ * **💻 Trung Tâm Điều Khiển TUI Trực Quan** — Quản lý các tiến trình runtime, kiểm tra nhật ký (logs), đăng ký thư mục làm việc và sửa đổi cấu hình trực tiếp từ giao diện terminal.
20
+ * **🤖 Terminal PTY Qua Telegram** — Thực thi và điều khiển các phiên shell tương tác thời gian thực (PowerShell, Bash, Codex hoặc Antigravity) từ xa thông qua Telegram.
21
+ * **⚙️ Trình Cấu Hình Động Trực Tiếp** — Thay đổi các tham số môi trường động thông qua menu `/config` bằng các phím inline Telegram hoặc trực tiếp trên CLI.
22
+ * **📂 Quản Lý Workspace Linh Hoạt** — Điều hướng và chuyển đổi nhanh chóng giữa các thư mục làm việc khác nhau trên máy chủ cục bộ.
23
+ * **🔄 Luồng Đầu Ra Được Tối Ưu Hóa** — Cơ chế gom cụm dữ liệu đầu ra thông minh với khoảng giãn cách (intervals) cấu hình được, giúp đảm bảo nhật ký terminal hiển thị mượt mà mà không vượt quá giới hạn API Telegram.
24
+ * **🚀 Khởi Động Cùng Hệ Điều Hành** — Dễ dàng cấu hình để chạy như một dịch vụ nền khi hệ thống khởi động (hỗ trợ Windows và Linux).
25
+ * **🌐 Hỗ Trợ Đa Ngôn Ngữ** — Bản dịch hoàn chỉnh cho tiếng Anh (`en`) và tiếng Việt (`vi`).
26
+ * **🛡️ Bảo Mật Nghiêm Ngặt** — Xác thực token và kiểm tra quyền hạn chặt chẽ, chỉ cho phép tài khoản Admin đã cấu hình điều khiển hệ thống.
27
+
28
+ ---
29
+
30
+ ## ⚙️ Kiến Trúc & Luồng Dữ Liệu
31
+
32
+ ```mermaid
33
+ graph TD
34
+ TelegramUser[📱 Telegram Client] <-->|Secure API Messages| TelegramServer[☁️ Telegram Bot API]
35
+ TelegramServer <-->|Grammy Framework| BotRuntime[🤖 Bot Runtime Process]
36
+
37
+ subgraph Local Server Environment
38
+ BotRuntime <-->|node-pty| PTY[💻 PTY Session <br> PowerShell / Bash / Codex]
39
+ BotRuntime <-->|Manage / Query| RuntimeState[📁 data/ & .env]
40
+
41
+ TUI[💻 Nonstop TUI Control Center] <-->|Read / Write| RuntimeState
42
+ TUI <-->|Control Daemon| BotRuntime
43
+ end
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 🕹️ Hướng Dẫn Sử Dụng
49
+
50
+ ### 1. Trung Tâm Điều Khiển TUI Cục Bộ
51
+ Chạy lệnh `npm start` (hoặc `npm run dev`) để mở giao diện quản lý trên terminal của bạn. Tại đây, bạn có thể:
52
+ * **Khởi động / Dừng (Start / Stop)** bot chạy ẩn.
53
+ * **Cấu hình Workspace**: Quản lý các thư mục mà phiên terminal được phép khởi chạy từ đó.
54
+ * **Tự động khởi động (Autostart)**: Thiết lập ứng dụng tự chạy khi hệ thống khởi động.
55
+ * **Xem logs**: Theo dõi nhật ký hoạt động của bot thời gian thực.
56
+
57
+ ### 2. Tương Tác Qua Telegram Bot
58
+ Khi bot đang hoạt động, bạn có thể tương tác với nó thông qua các lệnh và nút nhấn sau:
59
+
60
+ #### **📜 Các Lệnh Hệ Thống**
61
+ * `/start` — Mở menu chính tương tác.
62
+ * `/status` — Xem trạng thái hoạt động (số lượng workspace, các session đang chạy, preset).
63
+ * `/config` — Chỉnh sửa các tham số ứng dụng một cách nhanh chóng.
64
+ * `/send <lệnh>` — Gửi trực tiếp lệnh dạng văn bản thô tới phiên terminal hiện tại.
65
+ * `/help` — Hiển thị hướng dẫn và các lệnh hỗ trợ.
66
+
67
+ #### **⚡ Quản Lý Các Phiên Shell PTY**
68
+ 1. Chọn **⚡ Session** từ menu chính.
69
+ 2. Chọn một môi trường shell (ví dụ: **PowerShell**, **Bash**, **Codex**, hoặc **Antigravity**) để bắt đầu.
70
+ 3. Khi phiên hoạt động, hãy **bật Chế Độ Nhập (Input Mode)**.
71
+ 4. Bất kỳ tin nhắn văn bản thông thường nào bạn gửi tới bot (không bắt đầu bằng dấu `/`) sẽ được ghi thẳng vào phiên shell của bạn.
72
+ 5. Sử dụng các nút bấm trên bàn phím inline để gửi nhanh phím chức năng:
73
+ * **⛔ Esc** — Gửi phím Escape để hủy lệnh/tiến trình đang chạy.
74
+ * **⏎ Enter** — Gửi phím xuống dòng (chấp nhận lệnh).
75
+ * **▲ Up / ▼ Down** — Duyệt lại lịch sử các lệnh đã gõ.
76
+
77
+ #### **📂 Thư Mục Làm Việc (Workspaces)**
78
+ * Chọn **📁 Workspaces** từ menu chính để xem danh sách các thư mục được cấu hình trong `data/workspaces.json`.
79
+ * Việc chọn một workspace sẽ đổi thư mục hiện tại của phiên PTY tiếp theo sang thư mục đó.
80
+
81
+ #### **⚙️ Cấu Hình Hệ Thống Động**
82
+ * Nhấn nút **⚙️ Cấu hình** hoặc gửi lệnh `/config`.
83
+ * Nhấn vào bất kỳ trường cấu hình nào (ví dụ: *Token*, *Admin*, *Interval*, v.v.) và gửi giá trị mới thông qua tin nhắn để áp dụng ngay lập tức.
84
+ * Khi thay đổi `Telegram Bot Token`, bot sẽ tự động tải lại cấu hình và khởi động lại một cách an toàn.
85
+
86
+ ---
87
+
88
+ ## 🛠️ Hướng Dẫn Cài Đặt
89
+
90
+ ### 1. Yêu Cầu Hệ Thống
91
+ Hãy chắc chắn rằng máy tính của bạn đã cài đặt [Node.js](https://nodejs.org/) (v18+) và `npm`.
92
+
93
+ ### 2. Cài Đặt
94
+ Tải mã nguồn và cài đặt các thư viện cần thiết:
95
+ ```bash
96
+ git clone https://github.com/quangnv13/nonstop.git
97
+ cd nonstop
98
+ npm install
99
+ ```
100
+
101
+ ### 3. Biên Dịch Dự Án
102
+ Biên dịch các tệp TypeScript sang mã JavaScript chạy chính thức:
103
+ ```bash
104
+ npm run build
105
+ ```
106
+
107
+ ### 4. Khởi Chạy `nonstop`
108
+ Khởi động giao diện trung tâm điều khiển TUI:
109
+ ```bash
110
+ npm start
111
+ ```
112
+ > [!NOTE]
113
+ > Trong lần chạy đầu tiên, nếu tệp `.env` chưa tồn tại, `nonstop` sẽ tự động hiển thị **Trình hướng dẫn thiết lập (Setup Wizard)** để giúp bạn điền Token Telegram, tên người dùng Admin được phép truy cập, ngôn ngữ và cấu hình khởi động.
114
+
115
+ Với chế độ phát triển (hỗ trợ hot-reload):
116
+ ```bash
117
+ npm run dev
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 📁 Cấu Trúc Dự Án
123
+
124
+ ```text
125
+ nonstop/
126
+ ├── data/ # Lưu trữ dữ liệu (logs, workspaces.json, last-chat-id)
127
+ ├── src/ # Mã nguồn viết bằng TypeScript
128
+ │ ├── bot.ts # Xử lý bot Telegram & các callback query
129
+ │ ├── config.ts # Phân tích cấu hình, ghi tệp cấu hình & nạp biến môi trường
130
+ │ ├── runtime.ts # Quản lý shell session & tiến trình PTY
131
+ │ ├── ui.ts # Giao diện trung tâm điều khiển TUI
132
+ │ └── index.ts # Điểm khởi chạy ứng dụng
133
+ ├── dist/ # Mã JavaScript sau khi biên dịch
134
+ ├── .env # Lưu trữ cấu hình môi trường cục bộ (được bỏ qua bởi git)
135
+ └── package.json # Định nghĩa dự án & các script chạy lệnh
136
+ ```
137
+
138
+ ---
139
+
140
+ ## 🎛️ Cấu Hình Ban Đầu
141
+
142
+ Các cài đặt cấu hình nằm trong file `.env` tại thư mục gốc của dự án. Bạn có thể tạo từ tệp mẫu [`.env.example`](.env.example):
143
+
144
+ ```ini
145
+ TELEGRAM_BOT_TOKEN=your_telegram_bot_token
146
+ ADMIN_USERNAME=@your_telegram_username
147
+ TELEGRAM_USERNAME=@your_telegram_username
148
+ CLIENT_NAME=nonstop-local
149
+ APP_LANGUAGE=en
150
+ STARTUP_MODE=disabled
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 🛡️ Khuyến Nghị Bảo Mật
156
+
157
+ > [!WARNING]
158
+ > Do `nonstop` cung cấp quyền truy cập shell trực tiếp trên máy của bạn thông qua ứng dụng Telegram, hãy lưu ý các quy tắc bảo mật sau:
159
+ >
160
+ > 1. **Giữ Bí Mật Token Bot**: Tuyệt đối không commit tệp `.env` chứa token lên các kho lưu trữ công cộng.
161
+ > 2. **Kiểm Tra Kỹ Tên Admin**: Đảm bảo `ADMIN_USERNAME` được điền đúng (bao gồm cả ký tự `@` ở đầu) để tránh kẻ xấu lợi dụng.
162
+ > 3. **Chạy Với Quyền Hạn Hạn Chế**: Không nên chạy ứng dụng dưới các quyền quản trị cao nhất (như Administrator hoặc root) trừ khi thực sự cần thiết.
163
+
164
+ ---
165
+
166
+ ## 📄 Bản Quyền
167
+ Dự án được cấp phép theo Giấy Phép MIT - xem chi tiết tại tệp [LICENSE](LICENSE).