naturalshell-mac 1.0.0__tar.gz
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.
- naturalshell_mac-1.0.0/LICENSE +21 -0
- naturalshell_mac-1.0.0/MANIFEST.in +8 -0
- naturalshell_mac-1.0.0/PKG-INFO +316 -0
- naturalshell_mac-1.0.0/README.md +284 -0
- naturalshell_mac-1.0.0/naturalshell/__init__.py +32 -0
- naturalshell_mac-1.0.0/naturalshell/adapters/adapter_config.json +40 -0
- naturalshell_mac-1.0.0/naturalshell/adapters/adapters.safetensors +0 -0
- naturalshell_mac-1.0.0/naturalshell/ns.py +513 -0
- naturalshell_mac-1.0.0/naturalshell/shell_filter.py +189 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/PKG-INFO +316 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/SOURCES.txt +15 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/dependency_links.txt +1 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/entry_points.txt +2 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/requires.txt +2 -0
- naturalshell_mac-1.0.0/naturalshell_mac.egg-info/top_level.txt +1 -0
- naturalshell_mac-1.0.0/pyproject.toml +51 -0
- naturalshell_mac-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brian
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: naturalshell-mac
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Natural language to shell command converter with bilingual support
|
|
5
|
+
Author-email: Brian Chan <brianchan020516@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/brianchanyan/naturalshell
|
|
8
|
+
Project-URL: Documentation, https://github.com/brianchanyan/naturalshell#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/brianchanyan/naturalshell.git
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/brianchanyan/naturalshell/issues
|
|
11
|
+
Keywords: shell,cli,natural-language,ai,macos,terminal,chinese
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development
|
|
23
|
+
Classifier: Topic :: System :: Shells
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Classifier: Natural Language :: Chinese (Traditional)
|
|
26
|
+
Classifier: Natural Language :: English
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: mlx>=0.2.0
|
|
31
|
+
Requires-Dist: mlx-lm>=0.0.11
|
|
32
|
+
|
|
33
|
+
# NaturalShell (NS)
|
|
34
|
+
|
|
35
|
+
**Natural Language to Shell Command Converter with Bilingual Support**
|
|
36
|
+
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
[](https://www.apple.com/macos/)
|
|
40
|
+
|
|
41
|
+
> **Note: This is currently a BETA version.**
|
|
42
|
+
|
|
43
|
+
NaturalShell (NS) is a CLI tool that can convert natural language descriptions into shell commands. Optimized for macOS terminal usage with bilingual support (English and Traditional Chinese).
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Key Features
|
|
48
|
+
|
|
49
|
+
- **Bilingual Support**: Full support for both Traditional Chinese and English commands
|
|
50
|
+
- **High Accuracy**: 93.8% accuracy on 500 test cases
|
|
51
|
+
- **Smart Filtering**: Rule-based pre-filtering layer to reject irrelevant requests
|
|
52
|
+
- **macOS Optimized**: Specifically designed for macOS terminal usage
|
|
53
|
+
- **Safety First**: Two-stage verification mechanism ensures command safety
|
|
54
|
+
- **Runs Locally**: Powered by Apple MLX framework, runs completely offline after initial setup
|
|
55
|
+
- **Lightweight Model**: Based on Qwen2.5-3B-Instruct with LoRA fine-tuning
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
### Requirements
|
|
62
|
+
- **Operating System**: macOS (Apple Silicon or Intel)
|
|
63
|
+
- **Python**: 3.9 or higher
|
|
64
|
+
- **RAM**: 8GB+ recommended
|
|
65
|
+
|
|
66
|
+
### Install via pip
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install naturalshell
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After installation, the `ns` command will be available.
|
|
73
|
+
|
|
74
|
+
### Shell Integration
|
|
75
|
+
|
|
76
|
+
**Important:** Shell Integration is required for commands like `cd` and `export` to properly affect your current shell session.
|
|
77
|
+
|
|
78
|
+
To integrate NS into your shell:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Display integration commands
|
|
82
|
+
ns --init
|
|
83
|
+
|
|
84
|
+
# Add to your shell configuration
|
|
85
|
+
# For Zsh (default macOS shell):
|
|
86
|
+
ns --init >> ~/.zshrc
|
|
87
|
+
source ~/.zshrc
|
|
88
|
+
|
|
89
|
+
# For Bash:
|
|
90
|
+
ns --init >> ~/.bashrc
|
|
91
|
+
source ~/.bashrc
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Quick Start
|
|
97
|
+
|
|
98
|
+
### Basic Usage
|
|
99
|
+
|
|
100
|
+
Simply type natural language commands in your terminal:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# English examples
|
|
104
|
+
ns list all files in current directory
|
|
105
|
+
# Output: ls -la
|
|
106
|
+
|
|
107
|
+
ns find all Python files
|
|
108
|
+
# Output: find . -name "*.py"
|
|
109
|
+
|
|
110
|
+
ns show disk usage
|
|
111
|
+
# Output: df -h
|
|
112
|
+
|
|
113
|
+
# Additional examples
|
|
114
|
+
ns list all files in the current folder
|
|
115
|
+
# Output: ls -la
|
|
116
|
+
|
|
117
|
+
ns go to Desktop folder
|
|
118
|
+
# Output: cd ~/Desktop
|
|
119
|
+
|
|
120
|
+
ns search for all Python files
|
|
121
|
+
# Output: find . -name "*.py"
|
|
122
|
+
|
|
123
|
+
ns copy this file to Downloads folder
|
|
124
|
+
# Output: cp <file> ~/Downloads/
|
|
125
|
+
|
|
126
|
+
ns delete temporary files
|
|
127
|
+
# Output: rm -rf /tmp/*
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Examples
|
|
133
|
+
|
|
134
|
+
### File Operations
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
ns create a new folder called "project"
|
|
138
|
+
# mkdir project
|
|
139
|
+
|
|
140
|
+
ns copy all jpg files to Desktop
|
|
141
|
+
# cp *.jpg ~/Desktop/
|
|
142
|
+
|
|
143
|
+
ns find files modified in last 24 hours
|
|
144
|
+
# find . -mtime -1
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Git Operations
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
ns show git status
|
|
151
|
+
# git status
|
|
152
|
+
|
|
153
|
+
ns commit with message "fix bug"
|
|
154
|
+
# git commit -m "fix bug"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### System Information
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
ns show CPU usage
|
|
161
|
+
# top -l 1 | grep "CPU usage"
|
|
162
|
+
|
|
163
|
+
ns check available disk space
|
|
164
|
+
# df -h
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Package Management
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
ns install python using brew
|
|
171
|
+
# brew install python
|
|
172
|
+
|
|
173
|
+
ns update all brew packages
|
|
174
|
+
# brew upgrade
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Technical Architecture
|
|
180
|
+
|
|
181
|
+
### Two-Stage Pipeline
|
|
182
|
+
|
|
183
|
+
1. **Stage 1: Rule-based Filter**
|
|
184
|
+
- Quickly validates if requests are shell-command related
|
|
185
|
+
- Includes shell keywords, Chinese keywords, and path pattern detection
|
|
186
|
+
- Rejects irrelevant requests (e.g., weather queries, poetry composition)
|
|
187
|
+
|
|
188
|
+
2. **Stage 2: AI Model Inference**
|
|
189
|
+
- Uses Qwen2.5-3B-Instruct base model
|
|
190
|
+
- LoRA fine-tuned adapters (optimized for macOS shell commands)
|
|
191
|
+
- Apple MLX framework for accelerated inference
|
|
192
|
+
|
|
193
|
+
### Model Specifications
|
|
194
|
+
|
|
195
|
+
- **Base Model**: Qwen/Qwen2.5-3B-Instruct
|
|
196
|
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
|
197
|
+
- **Framework**: Apple MLX
|
|
198
|
+
- **Training Data**: Specialized macOS shell command dataset
|
|
199
|
+
- **Accuracy**: 93.8% (500 test cases)
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Supported Command Types
|
|
204
|
+
|
|
205
|
+
- File & Directory Operations: `ls`, `cd`, `mkdir`, `rm`, `cp`, `mv`, `find`, `grep`
|
|
206
|
+
- Version Control: `git` related commands
|
|
207
|
+
- Package Management: `brew`, `pip`, `npm`, `yarn`
|
|
208
|
+
- System Info: `top`, `ps`, `df`, `du`
|
|
209
|
+
- macOS Specific: `open`, `pbcopy`, `pbpaste`, `defaults`
|
|
210
|
+
- Network Tools: `curl`, `wget`, `ssh`, `ping`
|
|
211
|
+
- Compression: `tar`, `zip`, `unzip`, `gzip`
|
|
212
|
+
- Text Processing: `cat`, `head`, `tail`, `awk`, `sed`
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Safety Mechanisms
|
|
217
|
+
|
|
218
|
+
1. **Rule Filter**: Rejects non-shell related requests
|
|
219
|
+
2. **Command Validation**: AI model trained to emphasize safe command generation
|
|
220
|
+
3. **No Auto-execution**: Commands are only displayed by default, requiring manual execution or confirmation
|
|
221
|
+
4. **Scope Limitation**: Only processes macOS shell command related requests
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Development & Contributing
|
|
226
|
+
|
|
227
|
+
### Local Development
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Clone repository
|
|
231
|
+
git clone https://github.com/brianchanyan/naturalshell.git
|
|
232
|
+
cd naturalshell
|
|
233
|
+
|
|
234
|
+
# Install in development mode
|
|
235
|
+
pip install -e .
|
|
236
|
+
|
|
237
|
+
# Run tests
|
|
238
|
+
python -m pytest tests/
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Testing
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Test the rule-based filter
|
|
245
|
+
python naturalshell/shell_filter.py
|
|
246
|
+
|
|
247
|
+
# Test the full pipeline
|
|
248
|
+
ns "your test query"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Troubleshooting
|
|
254
|
+
|
|
255
|
+
### Model Download Issues
|
|
256
|
+
|
|
257
|
+
On first run, NS will automatically download the Qwen2.5-3B-Instruct model (approximately 6GB). If download fails:
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Manually download model
|
|
261
|
+
python3 -c "from mlx_lm import load; load('Qwen/Qwen2.5-3B-Instruct')"
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Out of Memory
|
|
265
|
+
|
|
266
|
+
If you encounter memory issues, try closing other applications or restarting your terminal.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Known Limitations
|
|
271
|
+
|
|
272
|
+
- macOS only (depends on MLX framework)
|
|
273
|
+
- Requires sufficient memory (8GB+ recommended)
|
|
274
|
+
- First run requires downloading approximately 6GB model
|
|
275
|
+
- Does not support complex multi-line script generation
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## Changelog
|
|
280
|
+
|
|
281
|
+
### v1.0.0 (2026-02-21)
|
|
282
|
+
- Initial release
|
|
283
|
+
- 93.8% accuracy
|
|
284
|
+
- Bilingual support (English and Traditional Chinese)
|
|
285
|
+
- Two-stage processing architecture
|
|
286
|
+
- Complete macOS shell command support
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT License - See [LICENSE](LICENSE) file for details
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Author
|
|
297
|
+
|
|
298
|
+
**Brian** - [GitHub](https://github.com/brianchanyan)
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Acknowledgments
|
|
303
|
+
|
|
304
|
+
- **Qwen Team** - For providing excellent base model
|
|
305
|
+
- **Apple MLX** - For efficient machine learning framework
|
|
306
|
+
- **Community Contributors** - Thanks for all testing and feedback
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## Links
|
|
311
|
+
|
|
312
|
+
- [PyPI Package](https://pypi.org/project/naturalshell/)
|
|
313
|
+
- [GitHub Repository](https://github.com/brianchanyan/naturalshell)
|
|
314
|
+
- [Issue Tracker](https://github.com/brianchanyan/naturalshell/issues)
|
|
315
|
+
- [Documentation](https://github.com/brianchanyan/naturalshell#readme)
|
|
316
|
+
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# NaturalShell (NS)
|
|
2
|
+
|
|
3
|
+
**Natural Language to Shell Command Converter with Bilingual Support**
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.python.org/downloads/)
|
|
7
|
+
[](https://www.apple.com/macos/)
|
|
8
|
+
|
|
9
|
+
> **Note: This is currently a BETA version.**
|
|
10
|
+
|
|
11
|
+
NaturalShell (NS) is a CLI tool that can convert natural language descriptions into shell commands. Optimized for macOS terminal usage with bilingual support (English and Traditional Chinese).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Key Features
|
|
16
|
+
|
|
17
|
+
- **Bilingual Support**: Full support for both Traditional Chinese and English commands
|
|
18
|
+
- **High Accuracy**: 93.8% accuracy on 500 test cases
|
|
19
|
+
- **Smart Filtering**: Rule-based pre-filtering layer to reject irrelevant requests
|
|
20
|
+
- **macOS Optimized**: Specifically designed for macOS terminal usage
|
|
21
|
+
- **Safety First**: Two-stage verification mechanism ensures command safety
|
|
22
|
+
- **Runs Locally**: Powered by Apple MLX framework, runs completely offline after initial setup
|
|
23
|
+
- **Lightweight Model**: Based on Qwen2.5-3B-Instruct with LoRA fine-tuning
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
### Requirements
|
|
30
|
+
- **Operating System**: macOS (Apple Silicon or Intel)
|
|
31
|
+
- **Python**: 3.9 or higher
|
|
32
|
+
- **RAM**: 8GB+ recommended
|
|
33
|
+
|
|
34
|
+
### Install via pip
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install naturalshell
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
After installation, the `ns` command will be available.
|
|
41
|
+
|
|
42
|
+
### Shell Integration
|
|
43
|
+
|
|
44
|
+
**Important:** Shell Integration is required for commands like `cd` and `export` to properly affect your current shell session.
|
|
45
|
+
|
|
46
|
+
To integrate NS into your shell:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Display integration commands
|
|
50
|
+
ns --init
|
|
51
|
+
|
|
52
|
+
# Add to your shell configuration
|
|
53
|
+
# For Zsh (default macOS shell):
|
|
54
|
+
ns --init >> ~/.zshrc
|
|
55
|
+
source ~/.zshrc
|
|
56
|
+
|
|
57
|
+
# For Bash:
|
|
58
|
+
ns --init >> ~/.bashrc
|
|
59
|
+
source ~/.bashrc
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
### Basic Usage
|
|
67
|
+
|
|
68
|
+
Simply type natural language commands in your terminal:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# English examples
|
|
72
|
+
ns list all files in current directory
|
|
73
|
+
# Output: ls -la
|
|
74
|
+
|
|
75
|
+
ns find all Python files
|
|
76
|
+
# Output: find . -name "*.py"
|
|
77
|
+
|
|
78
|
+
ns show disk usage
|
|
79
|
+
# Output: df -h
|
|
80
|
+
|
|
81
|
+
# Additional examples
|
|
82
|
+
ns list all files in the current folder
|
|
83
|
+
# Output: ls -la
|
|
84
|
+
|
|
85
|
+
ns go to Desktop folder
|
|
86
|
+
# Output: cd ~/Desktop
|
|
87
|
+
|
|
88
|
+
ns search for all Python files
|
|
89
|
+
# Output: find . -name "*.py"
|
|
90
|
+
|
|
91
|
+
ns copy this file to Downloads folder
|
|
92
|
+
# Output: cp <file> ~/Downloads/
|
|
93
|
+
|
|
94
|
+
ns delete temporary files
|
|
95
|
+
# Output: rm -rf /tmp/*
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
### File Operations
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
ns create a new folder called "project"
|
|
106
|
+
# mkdir project
|
|
107
|
+
|
|
108
|
+
ns copy all jpg files to Desktop
|
|
109
|
+
# cp *.jpg ~/Desktop/
|
|
110
|
+
|
|
111
|
+
ns find files modified in last 24 hours
|
|
112
|
+
# find . -mtime -1
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Git Operations
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
ns show git status
|
|
119
|
+
# git status
|
|
120
|
+
|
|
121
|
+
ns commit with message "fix bug"
|
|
122
|
+
# git commit -m "fix bug"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### System Information
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
ns show CPU usage
|
|
129
|
+
# top -l 1 | grep "CPU usage"
|
|
130
|
+
|
|
131
|
+
ns check available disk space
|
|
132
|
+
# df -h
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Package Management
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
ns install python using brew
|
|
139
|
+
# brew install python
|
|
140
|
+
|
|
141
|
+
ns update all brew packages
|
|
142
|
+
# brew upgrade
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Technical Architecture
|
|
148
|
+
|
|
149
|
+
### Two-Stage Pipeline
|
|
150
|
+
|
|
151
|
+
1. **Stage 1: Rule-based Filter**
|
|
152
|
+
- Quickly validates if requests are shell-command related
|
|
153
|
+
- Includes shell keywords, Chinese keywords, and path pattern detection
|
|
154
|
+
- Rejects irrelevant requests (e.g., weather queries, poetry composition)
|
|
155
|
+
|
|
156
|
+
2. **Stage 2: AI Model Inference**
|
|
157
|
+
- Uses Qwen2.5-3B-Instruct base model
|
|
158
|
+
- LoRA fine-tuned adapters (optimized for macOS shell commands)
|
|
159
|
+
- Apple MLX framework for accelerated inference
|
|
160
|
+
|
|
161
|
+
### Model Specifications
|
|
162
|
+
|
|
163
|
+
- **Base Model**: Qwen/Qwen2.5-3B-Instruct
|
|
164
|
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
|
165
|
+
- **Framework**: Apple MLX
|
|
166
|
+
- **Training Data**: Specialized macOS shell command dataset
|
|
167
|
+
- **Accuracy**: 93.8% (500 test cases)
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Supported Command Types
|
|
172
|
+
|
|
173
|
+
- File & Directory Operations: `ls`, `cd`, `mkdir`, `rm`, `cp`, `mv`, `find`, `grep`
|
|
174
|
+
- Version Control: `git` related commands
|
|
175
|
+
- Package Management: `brew`, `pip`, `npm`, `yarn`
|
|
176
|
+
- System Info: `top`, `ps`, `df`, `du`
|
|
177
|
+
- macOS Specific: `open`, `pbcopy`, `pbpaste`, `defaults`
|
|
178
|
+
- Network Tools: `curl`, `wget`, `ssh`, `ping`
|
|
179
|
+
- Compression: `tar`, `zip`, `unzip`, `gzip`
|
|
180
|
+
- Text Processing: `cat`, `head`, `tail`, `awk`, `sed`
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Safety Mechanisms
|
|
185
|
+
|
|
186
|
+
1. **Rule Filter**: Rejects non-shell related requests
|
|
187
|
+
2. **Command Validation**: AI model trained to emphasize safe command generation
|
|
188
|
+
3. **No Auto-execution**: Commands are only displayed by default, requiring manual execution or confirmation
|
|
189
|
+
4. **Scope Limitation**: Only processes macOS shell command related requests
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Development & Contributing
|
|
194
|
+
|
|
195
|
+
### Local Development
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Clone repository
|
|
199
|
+
git clone https://github.com/brianchanyan/naturalshell.git
|
|
200
|
+
cd naturalshell
|
|
201
|
+
|
|
202
|
+
# Install in development mode
|
|
203
|
+
pip install -e .
|
|
204
|
+
|
|
205
|
+
# Run tests
|
|
206
|
+
python -m pytest tests/
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Testing
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Test the rule-based filter
|
|
213
|
+
python naturalshell/shell_filter.py
|
|
214
|
+
|
|
215
|
+
# Test the full pipeline
|
|
216
|
+
ns "your test query"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Troubleshooting
|
|
222
|
+
|
|
223
|
+
### Model Download Issues
|
|
224
|
+
|
|
225
|
+
On first run, NS will automatically download the Qwen2.5-3B-Instruct model (approximately 6GB). If download fails:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Manually download model
|
|
229
|
+
python3 -c "from mlx_lm import load; load('Qwen/Qwen2.5-3B-Instruct')"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Out of Memory
|
|
233
|
+
|
|
234
|
+
If you encounter memory issues, try closing other applications or restarting your terminal.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Known Limitations
|
|
239
|
+
|
|
240
|
+
- macOS only (depends on MLX framework)
|
|
241
|
+
- Requires sufficient memory (8GB+ recommended)
|
|
242
|
+
- First run requires downloading approximately 6GB model
|
|
243
|
+
- Does not support complex multi-line script generation
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Changelog
|
|
248
|
+
|
|
249
|
+
### v1.0.0 (2026-02-21)
|
|
250
|
+
- Initial release
|
|
251
|
+
- 93.8% accuracy
|
|
252
|
+
- Bilingual support (English and Traditional Chinese)
|
|
253
|
+
- Two-stage processing architecture
|
|
254
|
+
- Complete macOS shell command support
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT License - See [LICENSE](LICENSE) file for details
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Author
|
|
265
|
+
|
|
266
|
+
**Brian** - [GitHub](https://github.com/brianchanyan)
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Acknowledgments
|
|
271
|
+
|
|
272
|
+
- **Qwen Team** - For providing excellent base model
|
|
273
|
+
- **Apple MLX** - For efficient machine learning framework
|
|
274
|
+
- **Community Contributors** - Thanks for all testing and feedback
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Links
|
|
279
|
+
|
|
280
|
+
- [PyPI Package](https://pypi.org/project/naturalshell/)
|
|
281
|
+
- [GitHub Repository](https://github.com/brianchanyan/naturalshell)
|
|
282
|
+
- [Issue Tracker](https://github.com/brianchanyan/naturalshell/issues)
|
|
283
|
+
- [Documentation](https://github.com/brianchanyan/naturalshell#readme)
|
|
284
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NaturalShell - Natural Language to Shell Command Converter
|
|
3
|
+
|
|
4
|
+
A powerful CLI tool that converts natural language descriptions into shell commands
|
|
5
|
+
using AI, specifically optimized for macOS terminal usage.
|
|
6
|
+
|
|
7
|
+
Features:
|
|
8
|
+
- Natural language to shell command conversion
|
|
9
|
+
- Bilingual support (English and Traditional Chinese)
|
|
10
|
+
- Rule-based safety filters
|
|
11
|
+
- Optimized for macOS
|
|
12
|
+
- 93.8% accuracy on 500 test cases
|
|
13
|
+
|
|
14
|
+
Example:
|
|
15
|
+
$ ns list all files in current directory
|
|
16
|
+
-> ls -la
|
|
17
|
+
|
|
18
|
+
$ ns 進入桌面資料夾
|
|
19
|
+
-> cd ~/Desktop
|
|
20
|
+
|
|
21
|
+
For more information, visit: https://github.com/brianchanyan/naturalshell
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
__version__ = "1.0.0"
|
|
25
|
+
__author__ = "Brian Chan"
|
|
26
|
+
__license__ = "MIT"
|
|
27
|
+
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
PACKAGE_DIR = Path(__file__).parent
|
|
31
|
+
|
|
32
|
+
__all__ = ["__version__", "__author__", "__license__", "PACKAGE_DIR"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"adapter_path": "/Users/brian/Desktop/NaturalShell/adapters",
|
|
3
|
+
"batch_size": 4,
|
|
4
|
+
"config": null,
|
|
5
|
+
"data": "/Users/brian/Desktop/NaturalShell/training_data/mlx_data",
|
|
6
|
+
"fine_tune_type": "lora",
|
|
7
|
+
"grad_accumulation_steps": 1,
|
|
8
|
+
"grad_checkpoint": false,
|
|
9
|
+
"iters": 100,
|
|
10
|
+
"learning_rate": 1e-06,
|
|
11
|
+
"lora_parameters": {
|
|
12
|
+
"rank": 8,
|
|
13
|
+
"dropout": 0.0,
|
|
14
|
+
"scale": 20.0
|
|
15
|
+
},
|
|
16
|
+
"lr_schedule": null,
|
|
17
|
+
"mask_prompt": false,
|
|
18
|
+
"max_seq_length": 2048,
|
|
19
|
+
"model": "Qwen/Qwen2.5-3B-Instruct",
|
|
20
|
+
"num_layers": 16,
|
|
21
|
+
"optimizer": "adam",
|
|
22
|
+
"optimizer_config": {
|
|
23
|
+
"adam": {},
|
|
24
|
+
"adamw": {},
|
|
25
|
+
"muon": {},
|
|
26
|
+
"sgd": {},
|
|
27
|
+
"adafactor": {}
|
|
28
|
+
},
|
|
29
|
+
"project_name": null,
|
|
30
|
+
"report_to": null,
|
|
31
|
+
"resume_adapter_file": "/Users/brian/Desktop/NaturalShell/adapters/r9_iter50_adapters.safetensors",
|
|
32
|
+
"save_every": 25,
|
|
33
|
+
"seed": 0,
|
|
34
|
+
"steps_per_eval": 25,
|
|
35
|
+
"steps_per_report": 25,
|
|
36
|
+
"test": false,
|
|
37
|
+
"test_batches": 500,
|
|
38
|
+
"train": true,
|
|
39
|
+
"val_batches": 25
|
|
40
|
+
}
|
|
Binary file
|