hintshell 0.1.0-beta.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.md ADDED
@@ -0,0 +1,211 @@
1
+ # 🧠 HintShell — AI-Powered Terminal Auto-Suggestion Engine (Rust CLI)
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/hintshell?color=red&label=npm%20beta)](https://www.npmjs.com/package/hintshell)
4
+ [![Rust CLI](https://img.shields.io/badge/Language-Rust-orange.svg)](https://www.rust-lang.org/)
5
+ [![Cross Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20macOS%20%7C%20Linux-blue.svg)]()
6
+ [![Shells](https://img.shields.io/badge/Shell-PowerShell%20%7C%20Bash%20%7C%20Zsh-4D4D4D.svg)]()
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ **HintShell** is a cross-platform, fuzzy-matching command intelligence engine built in Rust. It learns your terminal habits to provide real-time auto-suggestions and boosts your command-line productivity.
10
+
11
+ *(Gợi ý lệnh terminal thông minh dựa trên lịch sử sử dụng của bạn. HintShell học từ mỗi lệnh bạn gõ, kết hợp fuzzy matching + frequency scoring để gợi ý chính xác nhất.)*
12
+
13
+ ---
14
+
15
+ ## ✨ Features
16
+
17
+ - 🔮 **Auto-suggest real-time** (PowerShell) — gợi ý hiện ngay khi gõ
18
+ - 🔍 **Tab → fzf picker** (Bash/Zsh) — nhấn Tab để chọn lệnh
19
+ - 📊 **Fuzzy matching** — gõ sai vẫn tìm được lệnh đúng
20
+ - 🧮 **Frequency scoring** — lệnh dùng nhiều xếp trên
21
+ - 🖥️ **Cross-platform** — Windows, macOS, Linux
22
+ - 🐚 **Multi-shell** — PowerShell, Bash, Zsh
23
+
24
+ ## 🏗️ Architecture
25
+
26
+ ```
27
+ ┌─────────────┐ IPC ┌──────────────────┐
28
+ │ hintshell │◄────────────►│ hintshell-core │
29
+ │ (CLI) │ Named Pipe │ (Daemon) │
30
+ │ │ or UDS │ SQLite + Fuzzy │
31
+ └─────────────┘ └──────────────────┘
32
+ ▲
33
+ │ eval "$(hintshell hook bash)"
34
+ │ Import-Module HintShellModule
35
+ ▼
36
+ ┌─────────────────────────┐
37
+ │ Shell Integration │
38
+ │ PowerShell / Bash / Zsh │
39
+ └─────────────────────────┘
40
+ ```
41
+
42
+ - **hintshell** — CLI client, gửi request qua IPC
43
+ - **hintshell-core** — Daemon chạy nền, quản lý SQLite + suggestion engine
44
+ - **IPC** — Named Pipe (Windows) / Unix Domain Socket (Linux/macOS)
45
+
46
+ ---
47
+
48
+ ## 🚀 Quick Start (Recommended)
49
+
50
+ Cài đặt cực kỳ đơn giản qua **NPM** (hỗ trợ Windows, Linux, macOS):
51
+
52
+ ```bash
53
+ # 1. Cài đặt global
54
+ npm install -g hintshell
55
+
56
+ # 2. Khởi tạo (tự động cấu hình shell)
57
+ hintshell init
58
+
59
+ # 3. Khởi động lại terminal hoặc reload config
60
+ # PowerShell: . $PROFILE
61
+ # Bash/Zsh: source ~/.bashrc (hoặc ~/.zshrc)
62
+ ```
63
+
64
+ ### Build from Source
65
+
66
+ Nếu bạn muốn tự build từ mã nguồn:
67
+
68
+ ```bash
69
+ git clone https://github.com/philau2512/hintshell.git
70
+ cd hintshell
71
+ cargo build --release
72
+ ./target/release/hintshell init
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 🏗️ Architecture
78
+
79
+ ```
80
+ ┌─────────────┐ IPC ┌──────────────────┐
81
+ │ hintshell │◄────────────►│ hintshell-core │
82
+ │ (CLI) │ Named Pipe │ (Daemon) │
83
+ │ │ or UDS │ SQLite + Fuzzy │
84
+ └─────────────┘ └──────────────────┘
85
+ ▲
86
+ │ eval "$(hintshell hook bash)"
87
+ │ Import-Module HintShellModule
88
+ ▼
89
+ ┌─────────────────────────┐
90
+ │ Shell Integration │
91
+ │ PowerShell / Bash / Zsh │
92
+ └─────────────────────────┘
93
+ ```
94
+
95
+ - **hintshell** — CLI client, gửi request qua IPC
96
+ - **hintshell-core** — Daemon chạy nền, quản lý SQLite + suggestion engine
97
+ - **IPC** — Named Pipe (Windows) / Unix Domain Socket (Linux/macOS)
98
+
99
+ ---
100
+
101
+ ## 📖 Usage
102
+
103
+ ### PowerShell (Auto-suggest)
104
+
105
+ Gõ lệnh bình thường → gợi ý tự động hiện dưới dạng overlay:
106
+
107
+ ```
108
+ PS> git ch
109
+ → git checkout main (12x) [1/30]
110
+ git cherry-pick (3x) [2/30]
111
+ ```
112
+
113
+ - **↑/↓** — chọn gợi ý
114
+ - **Tab** — chấp nhận
115
+ - **Esc** — đóng
116
+ - **Enter** — thực thi lệnh hiện tại
117
+
118
+ ### Bash / Zsh (Tab → fzf)
119
+
120
+ Gõ lệnh → nhấn **Tab**:
121
+
122
+ ```bash
123
+ $ docker # nhấn Tab
124
+ 🧠 HintShell>
125
+ docker compose up -d
126
+ docker ps -a
127
+ docker build -t myapp .
128
+ ```
129
+
130
+ - **Tab/Enter** — chọn
131
+ - **Esc** — hủy
132
+
133
+ ### CLI Commands
134
+
135
+ ```bash
136
+ hintshell status # Xem trạng thái daemon
137
+ hintshell stop # Dừng daemon
138
+ hintshell start # Khởi động lại daemon
139
+ hintshell init # Chạy lại bộ cài đặt
140
+ ```
141
+
142
+ ---
143
+
144
+ ## 🐧 Platform Notes
145
+
146
+ ### Linux / WSL
147
+
148
+ ```bash
149
+ # Cài dependencies
150
+ sudo apt install -y build-essential fzf
151
+
152
+ # Build & install
153
+ cargo build --release
154
+ ./target/release/hintshell init
155
+ source ~/.bashrc
156
+ ```
157
+
158
+ ### macOS
159
+
160
+ ```bash
161
+ brew install fzf
162
+ cargo build --release
163
+ ./target/release/hintshell init
164
+ source ~/.zshrc
165
+ ```
166
+
167
+ ### Windows (PowerShell)
168
+
169
+ ```powershell
170
+ cargo build --release
171
+ .\target\release\hintshell.exe init
172
+ . $PROFILE
173
+ ```
174
+
175
+ ---
176
+
177
+ ## 📁 File Structure
178
+
179
+ ```
180
+ ~/.hintshell/
181
+ ├── bin/
182
+ │ ├── hintshell # CLI binary
183
+ │ └── hintshell-core # Daemon binary
184
+ ├── module/
185
+ │ └── HintShellModule/ # PowerShell module
186
+ └── history.db # SQLite database
187
+ ```
188
+
189
+ ---
190
+
191
+ ## 🛠️ Development
192
+
193
+ ```bash
194
+ # Build debug
195
+ cargo build
196
+
197
+ # Run CLI trực tiếp
198
+ cargo run --bin hintshell -- status
199
+
200
+ # Run daemon trực tiếp
201
+ cargo run --bin hintshell-core
202
+
203
+ # Reload nhanh (PowerShell)
204
+ .\reload-hintshell.ps1
205
+ ```
206
+
207
+ ---
208
+
209
+ ## 📄 License
210
+
211
+ MIT
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * HintShell CLI wrapper
5
+ * Finds the platform-specific binary in vendor/ and delegates all arguments to it.
6
+ */
7
+
8
+ const { execFileSync } = require("child_process");
9
+ const path = require("path");
10
+ const fs = require("fs");
11
+ const os = require("os");
12
+
13
+ const vendorDir = path.join(__dirname, "..", "vendor");
14
+ const isWin = os.platform() === "win32";
15
+
16
+ // Determine which binary to run based on how this script was called
17
+ const calledAs = path.basename(process.argv[1], ".js");
18
+ let binaryName;
19
+
20
+ if (calledAs === "hs" || calledAs === "hintshell-wrapper") {
21
+ // If called as 'hs', try hs binary first, fallback to hintshell
22
+ binaryName = isWin ? "hs.exe" : "hs";
23
+ const hsPath = path.join(vendorDir, binaryName);
24
+ if (!fs.existsSync(hsPath)) {
25
+ binaryName = isWin ? "hintshell.exe" : "hintshell";
26
+ }
27
+ } else {
28
+ binaryName = isWin ? "hintshell.exe" : "hintshell";
29
+ }
30
+
31
+ const binaryPath = path.join(vendorDir, binaryName);
32
+
33
+ if (!fs.existsSync(binaryPath)) {
34
+ console.error("❌ HintShell binary not found.");
35
+ console.error(" Run: npm install -g hintshell");
36
+ console.error(` Expected at: ${binaryPath}`);
37
+ process.exit(1);
38
+ }
39
+
40
+ const args = process.argv.slice(2);
41
+
42
+ try {
43
+ execFileSync(binaryPath, args, { stdio: "inherit" });
44
+ } catch (err) {
45
+ process.exit(err.status || 1);
46
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "hintshell",
3
+ "version": "0.1.0-beta.1",
4
+ "description": "AI-Powered Terminal Auto-Suggestion Engine — learns your command history and suggests commands in real-time",
5
+ "keywords": [
6
+ "terminal",
7
+ "autocomplete",
8
+ "auto-suggest",
9
+ "shell",
10
+ "command-line",
11
+ "powershell",
12
+ "bash",
13
+ "zsh",
14
+ "cli",
15
+ "productivity",
16
+ "rust"
17
+ ],
18
+ "homepage": "https://github.com/philau2512/hintshell",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/philau2512/hintshell.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": "philau2512",
25
+ "bin": {
26
+ "hintshell": "bin/hintshell-wrapper.js",
27
+ "hs": "bin/hintshell-wrapper.js"
28
+ },
29
+ "files": [
30
+ "bin/",
31
+ "scripts/",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "scripts": {
36
+ "postinstall": "node scripts/npm-install.js"
37
+ },
38
+ "os": [
39
+ "win32",
40
+ "linux",
41
+ "darwin"
42
+ ],
43
+ "cpu": [
44
+ "x64",
45
+ "arm64"
46
+ ],
47
+ "engines": {
48
+ "node": ">=16"
49
+ }
50
+ }
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * npm postinstall script for HintShell
5
+ * Downloads the correct platform-specific binary from GitHub Releases.
6
+ */
7
+
8
+ const https = require("https");
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+ const { execSync } = require("child_process");
12
+ const os = require("os");
13
+
14
+ const REPO = "philau2512/hintshell";
15
+ const VERSION = require("../package.json").version;
16
+ const TAG = `v${VERSION}`;
17
+
18
+ const PLATFORM_MAP = {
19
+ "win32-x64": "x86_64-pc-windows-msvc",
20
+ "linux-x64": "x86_64-unknown-linux-gnu",
21
+ "linux-arm64": "aarch64-unknown-linux-gnu",
22
+ "darwin-x64": "x86_64-apple-darwin",
23
+ "darwin-arm64": "aarch64-apple-darwin",
24
+ };
25
+
26
+ const EXT_MAP = {
27
+ win32: ".zip",
28
+ linux: ".tar.gz",
29
+ darwin: ".tar.gz",
30
+ };
31
+
32
+ function getPlatformKey() {
33
+ const platform = os.platform();
34
+ const arch = os.arch();
35
+ return `${platform}-${arch}`;
36
+ }
37
+
38
+ function getDownloadUrl(target, ext) {
39
+ return `https://github.com/${REPO}/releases/download/${TAG}/hintshell-${target}${ext}`;
40
+ }
41
+
42
+ function downloadFile(url, dest) {
43
+ return new Promise((resolve, reject) => {
44
+ const follow = (url) => {
45
+ https.get(url, (res) => {
46
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
47
+ follow(res.headers.location);
48
+ return;
49
+ }
50
+ if (res.statusCode !== 200) {
51
+ reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
52
+ return;
53
+ }
54
+ const file = fs.createWriteStream(dest);
55
+ res.pipe(file);
56
+ file.on("finish", () => { file.close(); resolve(); });
57
+ file.on("error", reject);
58
+ }).on("error", reject);
59
+ };
60
+ follow(url);
61
+ });
62
+ }
63
+
64
+ function extractArchive(archivePath, destDir) {
65
+ const platform = os.platform();
66
+ if (platform === "win32") {
67
+ // Use PowerShell to extract zip
68
+ execSync(
69
+ `powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`,
70
+ { stdio: "inherit" }
71
+ );
72
+ } else {
73
+ execSync(`tar xzf "${archivePath}" -C "${destDir}"`, { stdio: "inherit" });
74
+ }
75
+ }
76
+
77
+ async function main() {
78
+ const platformKey = getPlatformKey();
79
+ const target = PLATFORM_MAP[platformKey];
80
+
81
+ if (!target) {
82
+ console.error(`❌ Unsupported platform: ${platformKey}`);
83
+ console.error(` Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
84
+ process.exit(1);
85
+ }
86
+
87
+ const ext = EXT_MAP[os.platform()];
88
+ const url = getDownloadUrl(target, ext);
89
+ const installDir = path.join(__dirname, "..", "vendor");
90
+ const archivePath = path.join(os.tmpdir(), `hintshell-${target}${ext}`);
91
+
92
+ console.log(`📦 Installing HintShell for ${platformKey}...`);
93
+ console.log(` Downloading from: ${url}`);
94
+
95
+ fs.mkdirSync(installDir, { recursive: true });
96
+
97
+ try {
98
+ await downloadFile(url, archivePath);
99
+ console.log(` Extracting...`);
100
+ extractArchive(archivePath, installDir);
101
+
102
+ // Make binaries executable on Unix
103
+ if (os.platform() !== "win32") {
104
+ const bins = ["hintshell", "hintshell-core", "hs"];
105
+ for (const bin of bins) {
106
+ const binPath = path.join(installDir, bin);
107
+ if (fs.existsSync(binPath)) {
108
+ fs.chmodSync(binPath, 0o755);
109
+ }
110
+ }
111
+ }
112
+
113
+ // Cleanup
114
+ fs.unlinkSync(archivePath);
115
+
116
+ console.log(`✅ HintShell installed successfully!`);
117
+ console.log(` Run 'hintshell init' to configure your shell.`);
118
+ } catch (err) {
119
+ console.error(`❌ Installation failed: ${err.message}`);
120
+ console.error(` You can manually download from: https://github.com/${REPO}/releases`);
121
+ process.exit(1);
122
+ }
123
+ }
124
+
125
+ main();