@austinthesing/magic-shell 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Magic Shell Contributors
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.
package/README.md ADDED
@@ -0,0 +1,542 @@
1
+ # Magic Shell
2
+
3
+ > Transform natural language into terminal commands with built-in safety features.
4
+
5
+ Magic Shell is an open-source CLI tool that translates plain English (or any natural language) into shell commands using AI. It supports multiple AI providers, includes a beautiful interactive TUI mode, and features a comprehensive safety system to protect you from dangerous commands.
6
+
7
+ ## Features
8
+
9
+ - **Natural Language Translation**: Describe what you want to do in plain English
10
+ - **Multiple AI Providers**: OpenCode Zen (with free models!) and OpenRouter
11
+ - **Interactive TUI Mode**: Full-featured terminal interface with themes
12
+ - **Command Safety Analysis**: Multi-level safety checks before executing commands
13
+ - **Cross-Platform**: macOS, Linux, and Windows support
14
+ - **Shell-Aware**: Automatically detects and adapts to your shell (bash, zsh, fish, PowerShell, etc.)
15
+ - **Secure Credential Storage**: Uses system keychain (macOS Keychain, Linux secret-tool, Windows Credential Manager)
16
+ - **Command History**: Context-aware translations based on your recent commands
17
+ - **Beautiful Themes**: 8 built-in themes including Tokyo Night, Catppuccin, Dracula, and more
18
+
19
+ ## Installation
20
+
21
+ ### Quick Install (Recommended)
22
+
23
+ **macOS / Linux:**
24
+ ```bash
25
+ curl -fsSL https://raw.githubusercontent.com/austin-thesing/magic-shell/main/install.sh | bash
26
+ ```
27
+
28
+ **Windows (PowerShell):**
29
+ ```powershell
30
+ irm https://raw.githubusercontent.com/austin-thesing/magic-shell/main/install.ps1 | iex
31
+ ```
32
+
33
+ ### Via Package Manager
34
+
35
+ ```bash
36
+ # Install globally with bun (recommended)
37
+ bun add -g @austinthesing/magic-shell
38
+
39
+ # Or with npm
40
+ npm install -g @austinthesing/magic-shell
41
+
42
+ # Or with yarn
43
+ yarn global add @austinthesing/magic-shell
44
+
45
+ # Or with pnpm
46
+ pnpm add -g @austinthesing/magic-shell
47
+ ```
48
+
49
+ ### Via Homebrew (macOS/Linux)
50
+
51
+ ```bash
52
+ brew install austin-thesing/tap/magic-shell
53
+ ```
54
+
55
+ ### From Source
56
+
57
+ **Prerequisites:** [Bun](https://bun.sh) runtime (v1.0 or higher)
58
+
59
+ ```bash
60
+ # Clone the repository
61
+ git clone https://github.com/austin-thesing/magic-shell.git
62
+ cd magic-shell
63
+
64
+ # Install dependencies
65
+ bun install
66
+
67
+ # Build
68
+ bun run build
69
+
70
+ # Link globally (optional)
71
+ bun link
72
+ ```
73
+
74
+ ### Quick Start
75
+
76
+ ```bash
77
+ # Run setup to configure your API key
78
+ msh --setup
79
+
80
+ # Or set via environment variable
81
+ export OPENCODE_ZEN_API_KEY="your-key-here"
82
+ ```
83
+
84
+ ## Usage
85
+
86
+ Magic Shell can be invoked using `magic-shell`, `msh`, or `ms`.
87
+
88
+ ### Basic Commands
89
+
90
+ ```bash
91
+ # Translate a query to a command (prints the command)
92
+ msh "list all javascript files"
93
+ # Output: find . -name "*.js"
94
+
95
+ # Translate and execute
96
+ msh -x "show disk usage"
97
+
98
+ # Dry run - preview with safety analysis
99
+ msh -n "delete all node_modules folders"
100
+
101
+ # Launch interactive TUI mode
102
+ msh -i
103
+ # or just
104
+ msh
105
+ ```
106
+
107
+ ### Command Reference
108
+
109
+ | Command | Description |
110
+ |---------|-------------|
111
+ | `msh <query>` | Translate query to command and print it |
112
+ | `msh -x <query>` | Translate and execute the command |
113
+ | `msh -n <query>` | Dry run - show command with safety analysis |
114
+ | `msh -i, --interactive` | Launch interactive TUI mode |
115
+ | `msh --setup` | Configure API keys and provider |
116
+ | `msh --models` | List available models |
117
+ | `msh --model <id>` | Set default model |
118
+ | `msh --provider <name>` | Set provider (opencode-zen or openrouter) |
119
+ | `msh --themes` | List available themes |
120
+ | `msh --theme <name>` | Set color theme |
121
+ | `msh --help` | Show help |
122
+
123
+ ### Examples
124
+
125
+ ```bash
126
+ # File operations
127
+ msh "find all files larger than 100MB"
128
+ msh "count lines of code in this project"
129
+ msh "show the 10 most recently modified files"
130
+
131
+ # Git operations
132
+ msh "undo my last commit but keep changes"
133
+ msh "show commits from the last week"
134
+ msh "create a branch from main called feature-login"
135
+
136
+ # System operations
137
+ msh "check which process is using port 3000"
138
+ msh "show memory usage"
139
+ msh "list all running docker containers"
140
+
141
+ # Execute directly
142
+ msh -x "show current git branch"
143
+
144
+ # Pipe to clipboard (macOS)
145
+ msh "compress this folder to a zip file" | pbcopy
146
+ ```
147
+
148
+ ## Interactive TUI Mode
149
+
150
+ Launch with `msh` or `msh -i` for a full interactive experience.
151
+
152
+ ### Keyboard Shortcuts
153
+
154
+ All shortcuts use the `Ctrl+X` chord (press Ctrl+X, then the key):
155
+
156
+ | Shortcut | Action |
157
+ |----------|--------|
158
+ | `Ctrl+X P` | Open command palette |
159
+ | `Ctrl+X M` | Change model |
160
+ | `Ctrl+X S` | Switch provider |
161
+ | `Ctrl+X D` | Toggle dry-run mode |
162
+ | `Ctrl+X T` | Change theme |
163
+ | `Ctrl+X H` | Show history |
164
+ | `Ctrl+X C` | Show config |
165
+ | `Ctrl+X L` | Clear output |
166
+ | `Ctrl+X ?` | Show help |
167
+ | `Ctrl+X Q` | Exit |
168
+ | `Ctrl+C` | Exit / Cancel |
169
+ | `Esc` | Close dialogs |
170
+
171
+ ### Direct Commands in TUI
172
+
173
+ You can also type commands directly in the TUI:
174
+
175
+ - `!help` - Show help
176
+ - `!model` - Change model
177
+ - `!provider` - Switch provider
178
+ - `!dry` - Toggle dry-run mode
179
+ - `!config` - Show current configuration
180
+ - `!history` - Show command history
181
+ - `!clear` - Clear output
182
+
183
+ ## AI Providers
184
+
185
+ ### OpenCode Zen (Recommended)
186
+
187
+ OpenCode Zen provides curated models optimized for coding tasks, including **free models**.
188
+
189
+ **Free Models:**
190
+ - `grok-code` - xAI's Grok Code Fast 1
191
+ - `glm-4.7-free` - GLM 4.7
192
+ - `minimax-m2.1-free` - MiniMax M2.1
193
+ - `big-pickle` - Stealth model
194
+
195
+ **Premium Models:**
196
+ - Claude Sonnet 4.5, Claude Opus 4.5
197
+ - Gemini 3 Flash, Gemini 3 Pro
198
+ - Kimi K2, Kimi K2 Thinking
199
+ - Qwen3 Coder 480B
200
+ - And more...
201
+
202
+ Get your API key at: https://opencode.ai/auth
203
+
204
+ ### OpenRouter
205
+
206
+ Access to a wide variety of models from different providers.
207
+
208
+ **Free Models:**
209
+ - MiMo V2 Flash
210
+ - DeepSeek V3
211
+ - Gemini 2.5 Flash
212
+
213
+ **Premium Models:**
214
+ - Claude Sonnet 4.5, Claude Opus 4.5
215
+ - GPT 5.2 Codex
216
+ - Gemini 2.5 Pro
217
+ - DeepSeek R1
218
+ - And many more...
219
+
220
+ Get your API key at: https://openrouter.ai/keys
221
+
222
+ ## Safety System
223
+
224
+ Magic Shell includes a comprehensive safety analysis system that categorizes commands by risk level:
225
+
226
+ ### Severity Levels
227
+
228
+ | Level | Description | Examples |
229
+ |-------|-------------|----------|
230
+ | **Critical** | Could cause irreversible system damage | `rm -rf /`, fork bombs, disk overwrites |
231
+ | **High** | Significant changes or data loss risk | `sudo rm`, `kill -9 -1`, `shutdown` |
232
+ | **Medium** | Requires elevated privileges | `sudo`, `chmod`, package removal |
233
+ | **Low** | Worth reviewing | `git checkout`, `npm install` |
234
+
235
+ ### Safety Levels
236
+
237
+ Configure your preferred safety level:
238
+
239
+ - **Strict**: Confirm all potentially risky commands
240
+ - **Moderate** (default): Confirm high and critical severity commands
241
+ - **Relaxed**: Only confirm critical severity commands
242
+
243
+ ### Blocked Commands
244
+
245
+ Certain dangerous patterns are always blocked:
246
+ - Fork bombs
247
+ - Direct disk writes (`> /dev/sda`)
248
+ - Filesystem formatting (`mkfs`)
249
+ - Recursive permission changes on root (`chmod -R 777 /`)
250
+
251
+ ## Configuration
252
+
253
+ Configuration is stored in `~/.magic-shell/config.json`.
254
+
255
+ ### Config Options
256
+
257
+ ```json
258
+ {
259
+ "provider": "opencode-zen",
260
+ "defaultModel": "grok-code",
261
+ "safetyLevel": "moderate",
262
+ "dryRunByDefault": false,
263
+ "theme": "opencode",
264
+ "blockedCommands": [...],
265
+ "confirmedDangerousPatterns": [...]
266
+ }
267
+ ```
268
+
269
+ ### Environment Variables
270
+
271
+ | Variable | Description |
272
+ |----------|-------------|
273
+ | `OPENCODE_ZEN_API_KEY` | API key for OpenCode Zen |
274
+ | `OPENROUTER_API_KEY` | API key for OpenRouter |
275
+ | `DEBUG_API=1` | Enable API response debugging |
276
+
277
+ ## Themes
278
+
279
+ Magic Shell includes 8 beautiful themes:
280
+
281
+ - `opencode` (default) - Orange and blue tones
282
+ - `tokyonight` - Soft purple and blue
283
+ - `catppuccin` - Pastel Mocha variant
284
+ - `gruvbox` - Retro warm tones
285
+ - `nord` - Arctic cool blues
286
+ - `dracula` - Purple vampire vibes
287
+ - `one-dark` - Atom-inspired
288
+ - `matrix` - Classic green terminal
289
+
290
+ Change themes:
291
+ ```bash
292
+ # CLI
293
+ msh --theme tokyonight
294
+
295
+ # TUI
296
+ Ctrl+X T
297
+ ```
298
+
299
+ ## Shell Support
300
+
301
+ Magic Shell automatically detects and adapts to your shell:
302
+
303
+ - **Bash** - Full support with bash-specific syntax
304
+ - **Zsh** - Extended globbing and array syntax
305
+ - **Fish** - Fish-specific syntax (no `$()`, different variable syntax)
306
+ - **PowerShell / pwsh** - Cmdlet syntax and object pipelines
307
+ - **CMD** - Windows command syntax
308
+ - **Nushell** - Structured data syntax
309
+ - **POSIX sh** - Portable fallback
310
+
311
+ ## Platform Support
312
+
313
+ | Platform | Shell Detection | Keychain Storage |
314
+ |----------|-----------------|------------------|
315
+ | macOS | Full | macOS Keychain |
316
+ | Linux | Full | libsecret (secret-tool) |
317
+ | Windows | Full | Credential Manager |
318
+ | WSL | Full (detected) | libsecret |
319
+
320
+ ## Development
321
+
322
+ ```bash
323
+ # Run in development mode
324
+ bun run dev
325
+
326
+ # Run TUI in development mode
327
+ bun run dev:tui
328
+
329
+ # Type check
330
+ bun run typecheck
331
+
332
+ # Build for distribution
333
+ bun run build
334
+ ```
335
+
336
+ ### Project Structure
337
+
338
+ ```
339
+ src/
340
+ index.ts # CLI entry point
341
+ cli.ts # TUI mode
342
+ lib/
343
+ types.ts # Type definitions and model configs
344
+ config.ts # Configuration management
345
+ api.ts # AI provider integrations
346
+ safety.ts # Command safety analysis
347
+ theme.ts # Theme system
348
+ keychain.ts # Secure credential storage
349
+ shell.ts # Shell/platform detection
350
+ ```
351
+
352
+ ## Publishing to npm
353
+
354
+ ### Prerequisites
355
+
356
+ 1. Create an npm account at https://www.npmjs.com/signup
357
+ 2. Login to npm:
358
+ ```bash
359
+ npm login
360
+ ```
361
+
362
+ ### Preparing for Release
363
+
364
+ 1. **Update package.json** - Ensure these fields are set correctly:
365
+
366
+ ```json
367
+ {
368
+ "name": "@austinthesing/magic-shell",
369
+ "version": "0.1.0",
370
+ "description": "Natural language to terminal commands with safety features",
371
+ "main": "dist/index.js",
372
+ "bin": {
373
+ "magic-shell": "./dist/index.js",
374
+ "msh": "./dist/index.js",
375
+ "ms": "./dist/index.js"
376
+ },
377
+ "files": [
378
+ "dist",
379
+ "README.md",
380
+ "LICENSE"
381
+ ],
382
+ "repository": {
383
+ "type": "git",
384
+ "url": "https://github.com/austin-thesing/magic-shell.git"
385
+ },
386
+ "homepage": "https://github.com/austin-thesing/magic-shell#readme",
387
+ "bugs": {
388
+ "url": "https://github.com/austin-thesing/magic-shell/issues"
389
+ },
390
+ "keywords": [
391
+ "cli",
392
+ "terminal",
393
+ "natural-language",
394
+ "shell",
395
+ "ai",
396
+ "openrouter",
397
+ "opencode",
398
+ "command-line"
399
+ ],
400
+ "author": "Your Name <your@email.com>",
401
+ "license": "MIT"
402
+ }
403
+ ```
404
+
405
+ 2. **Build the project:**
406
+ ```bash
407
+ bun run build
408
+ ```
409
+
410
+ 3. **Test locally before publishing:**
411
+ ```bash
412
+ # Create a tarball
413
+ npm pack
414
+
415
+ # Install it globally to test
416
+ npm install -g ./magic-shell-0.1.0.tgz
417
+
418
+ # Test it works
419
+ msh --help
420
+
421
+ # Uninstall test version
422
+ npm uninstall -g magic-shell
423
+ ```
424
+
425
+ ### Publishing
426
+
427
+ ```bash
428
+ # Publish to npm (first time)
429
+ npm publish
430
+
431
+ # Publish with public access (for scoped packages like @your-username/magic-shell)
432
+ npm publish --access public
433
+ ```
434
+
435
+ ### Releasing New Versions
436
+
437
+ 1. **Update version** (follows [semver](https://semver.org/)):
438
+ ```bash
439
+ # Patch release (bug fixes): 0.1.0 -> 0.1.1
440
+ npm version patch
441
+
442
+ # Minor release (new features): 0.1.0 -> 0.2.0
443
+ npm version minor
444
+
445
+ # Major release (breaking changes): 0.1.0 -> 1.0.0
446
+ npm version major
447
+ ```
448
+
449
+ 2. **Push tags to GitHub:**
450
+ ```bash
451
+ git push origin main --tags
452
+ ```
453
+
454
+ 3. **Publish the new version:**
455
+ ```bash
456
+ npm publish
457
+ ```
458
+
459
+ ### Automated Releases with GitHub Actions
460
+
461
+ Create `.github/workflows/release.yml`:
462
+
463
+ ```yaml
464
+ name: Release
465
+
466
+ on:
467
+ push:
468
+ tags:
469
+ - 'v*'
470
+
471
+ jobs:
472
+ release:
473
+ runs-on: ubuntu-latest
474
+ steps:
475
+ - uses: actions/checkout@v4
476
+
477
+ - uses: oven-sh/setup-bun@v1
478
+ with:
479
+ bun-version: latest
480
+
481
+ - name: Install dependencies
482
+ run: bun install
483
+
484
+ - name: Build
485
+ run: bun run build
486
+
487
+ - name: Publish to npm
488
+ run: npm publish
489
+ env:
490
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
491
+
492
+ - name: Create GitHub Release
493
+ uses: softprops/action-gh-release@v1
494
+ with:
495
+ generate_release_notes: true
496
+ ```
497
+
498
+ Add your npm token to GitHub:
499
+ 1. Generate token at https://www.npmjs.com/settings/tokens (use "Automation" type)
500
+ 2. Add to repository secrets as `NPM_TOKEN`
501
+
502
+ ### Version Management Tips
503
+
504
+ - Use `npm version` commands - they automatically:
505
+ - Update `package.json` version
506
+ - Create a git commit
507
+ - Create a git tag
508
+
509
+ - Consider using [Changesets](https://github.com/changesets/changesets) for monorepo or complex versioning
510
+
511
+ - Add a `prepublishOnly` script to ensure builds are fresh:
512
+ ```json
513
+ {
514
+ "scripts": {
515
+ "prepublishOnly": "bun run build"
516
+ }
517
+ }
518
+ ```
519
+
520
+ ## Contributing
521
+
522
+ Contributions are welcome! Please feel free to submit a Pull Request.
523
+
524
+ 1. Fork the repository
525
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
526
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
527
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
528
+ 5. Open a Pull Request
529
+
530
+ ## License
531
+
532
+ MIT License - see [LICENSE](LICENSE) for details.
533
+
534
+ ## Acknowledgments
535
+
536
+ - Built with [Bun](https://bun.sh)
537
+ - TUI powered by [@opentui/core](https://github.com/opentui/core)
538
+ - Theme colors inspired by [OpenCode](https://github.com/anomalyco/opencode)
539
+
540
+ ---
541
+
542
+ **Magic Shell** - Type what you mean, execute what you need.